lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
/// @notice Backup function for activating token purchase
///  requires sender to be a member of the group or CLevel
/// @param _tokenId The ID of the Token group
function activatePurchase(uint256 _tokenId) external whenNotPaused {
    var group = tokenIndexToGroup[_tokenId];
    require(group.addressToContribution[msg.sender] > 0 ||
            msg.sender == ceoAddress ||
            msg.sender == cooAddress1 ||
            msg.sender == cooAddress2 ||
            msg.sender == cooAddress3 ||
            msg.sender == cfoAddress);

    // Safety check that enough money has been contributed to group
    var price = linkedContract.priceOf(_tokenId);
    require(group.contributedBalance >= price);

    // Safety check that token had not be purchased yet
    require(group.purchasePrice == 0);

    _purchase(_tokenId, price);
  }
// Solidity 0.4.18
/// @notice Allow user to leave purchase group; note that their contribution
///  will be added to their withdrawable balance, and not directly refunded.
///  User can call withdrawBalance to retrieve funds.
/// @param _tokenId The ID of the Token purchase group to be left
function leaveTokenGroup(uint256 _tokenId) external whenNotPaused {
    address userAdd = msg.sender;

    var group = tokenIndexToGroup[_tokenId];
    var contributor = userAddressToContributor[userAdd];

    // Safety check to prevent against an unexpected 0x0 default.
    require(_addressNotNull(userAdd));

    // Safety check to make sure group exists;
    require(group.exists);

    // Safety check to make sure group hasn't purchased token already
    require(group.purchasePrice == 0);

    // Safety checks to ensure contributor has contributed to group
    require(group.addressToContributorArrIndex[userAdd] > 0);
    require(contributor.tokenIdToGroupArrIndex[_tokenId] > 0);

    uint refundBalance = _clearContributorRecordInGroup(_tokenId, userAdd);
    _clearGroupRecordInContributor(_tokenId, userAdd);

    userAddressToContributor[userAdd].withdrawableBalance += refundBalance;
    FundsDeposited(userAdd, refundBalance);

    LeaveGroup(
      _tokenId,
      userAdd,
      tokenIndexToGroup[_tokenId].contributedBalance,
      refundBalance
    );
  }
// Solidity 0.4.18
/// @notice Allow user to leave purchase group; note that their contribution
///  and any funds they have in their withdrawableBalance will transfered to them.
/// @param _tokenId The ID of the Token purchase group to be left
function leaveTokenGroupAndWithdrawBalance(uint256 _tokenId) external whenNotPaused {
    address userAdd = msg.sender;

    var group = tokenIndexToGroup[_tokenId];
    var contributor = userAddressToContributor[userAdd];

    // Safety check to prevent against an unexpected 0x0 default.
    require(_addressNotNull(userAdd));

    // Safety check to make sure group exists;
    require(group.exists);

    // Safety check to make sure group hasn't purchased token already
    require(group.purchasePrice == 0);

    // Safety checks to ensure contributor has contributed to group
    require(group.addressToContributorArrIndex[userAdd] > 0);
    require(contributor.tokenIdToGroupArrIndex[_tokenId] > 0);

    uint refundBalance = _clearContributorRecordInGroup(_tokenId, userAdd);
    _clearGroupRecordInContributor(_tokenId, userAdd);

    userAddressToContributor[userAdd].withdrawableBalance += refundBalance;
    FundsDeposited(userAdd, refundBalance);

    _withdrawUserFunds(userAdd);

    LeaveGroup(
      _tokenId,
      userAdd,
      tokenIndexToGroup[_tokenId].contributedBalance,
      refundBalance
    );
  }
// Solidity 0.4.18
/// @dev In the event of needing a fork, this function moves all
///  of a group's contributors' contributions into their withdrawable balance.
/// @notice Group is dissolved after fn call
/// @param _tokenId The ID of the Token purchase group
function dissolveTokenGroup(uint256 _tokenId) external onlyCOO whenForking {
    var group = tokenIndexToGroup[_tokenId];

    // Safety check to make sure group exists and had not purchased a token
    require(group.exists);
    require(group.purchasePrice == 0);

    for (uint i = 0; i < tokenIndexToGroup[_tokenId].contributorArr.length; i++) {
      address userAdd = tokenIndexToGroup[_tokenId].contributorArr[i];

      var userContribution = group.addressToContribution[userAdd];

      _clearGroupRecordInContributor(_tokenId, userAdd);

      // clear contributor record on group
      tokenIndexToGroup[_tokenId].addressToContribution[userAdd] = 0;
      tokenIndexToGroup[_tokenId].addressToContributorArrIndex[userAdd] = 0;

      // move contributor's contribution to their withdrawable balance
      userAddressToContributor[userAdd].withdrawableBalance += userContribution;
      ProceedsDeposited(_tokenId, userAdd, userContribution);
    }
    activeGroups -= 1;
    tokenIndexToGroup[_tokenId].exists = false;
  }
// Solidity 0.4.18
/// @dev Backup fn to allow distribution of funds after sale,
///  for the special scenario where an alternate sale platform is used;
/// @notice Group is dissolved after fn call
/// @param _tokenId The ID of the Token purchase group
/// @param _amount Funds to be distributed
function distributeCustomSaleProceeds(uint256 _tokenId, uint256 _amount) external onlyCOO {
    var group = tokenIndexToGroup[_tokenId];

    // Safety check to make sure group exists and had purchased the token
    require(group.exists);
    require(group.purchasePrice > 0);
    require(_amount > 0);

    _distributeProceeds(_tokenId, _amount);
  }
// Solidity 0.4.18
/// @dev Distribute funds after a token is sold.
///  Group is dissolved after fn call
/// @param _tokenId The ID of the Token purchase group
function distributeSaleProceeds(uint256 _tokenId) external onlyCOO {
    var group = tokenIndexToGroup[_tokenId];

    // Safety check to make sure group exists and had purchased the token
    require(group.exists);
    require(group.purchasePrice > 0);

    // Safety check to make sure token had been sold
    uint256 currPrice = linkedContract.priceOf(_tokenId);
    uint256 soldPrice = _newPrice(group.purchasePrice);
    require(currPrice > soldPrice);

    uint256 paymentIntoContract = uint256(SafeMath.div(SafeMath.mul(soldPrice, 94), 100));
    _distributeProceeds(_tokenId, paymentIntoContract);
  }
// Solidity 0.4.18
/// @dev Backup fn to allow transfer of token out of
///  contract, for use where a purchase group wants to use an alternate
///  selling platform
/// @param _tokenId The ID of the Token purchase group
/// @param _to Address to transfer token to
function transferToken(uint256 _tokenId, address _to) external onlyCOO {
    var group = tokenIndexToGroup[_tokenId];

    // Safety check to make sure group exists and had purchased the token
    require(group.exists);
    require(group.purchasePrice > 0);

    linkedContract.transfer(_to, _tokenId);
  }
// Solidity 0.4.18
/// @dev Withdraws sale commission, CFO-only functionality
/// @param _to Address for commission to be sent to
function withdrawCommission(address _to) external onlyCFO {
    uint256 balance = commissionBalance;
    address transferee = (_to == address(0)) ? cfoAddress : _to;
    commissionBalance = 0;
    if (balance > 0) {
      transferee.transfer(balance);
    }
    FundsWithdrawn(transferee, balance);
  }
// Solidity 0.4.18
/// @dev Clears record of a Contributor from a Group's record
/// @param _tokenId Token ID of Group to be cleared
/// @param _userAdd Address of Contributor
function _clearContributorRecordInGroup(uint256 _tokenId, address _userAdd) private returns (uint256 refundBalance) {
    var group = tokenIndexToGroup[_tokenId];

    // Index was saved is 1 + the array's index, b/c 0 is the default value
    //  in a mapping.
    uint cIndex = group.addressToContributorArrIndex[_userAdd] - 1;
    uint lastCIndex = group.contributorArr.length - 1;
    refundBalance = group.addressToContribution[_userAdd];

    // clear contribution record in group
    tokenIndexToGroup[_tokenId].addressToContributorArrIndex[_userAdd] = 0;
    tokenIndexToGroup[_tokenId].addressToContribution[_userAdd] = 0;

    // move address in last position to deleted contributor's spot
    if (lastCIndex > 0) {
      tokenIndexToGroup[_tokenId].addressToContributorArrIndex[group.contributorArr[lastCIndex]] = cIndex;
      tokenIndexToGroup[_tokenId].contributorArr[cIndex] = group.contributorArr[lastCIndex];
    }

    tokenIndexToGroup[_tokenId].contributorArr.length -= 1;
    tokenIndexToGroup[_tokenId].contributedBalance -= refundBalance;
  }
// Solidity 0.7.1
/**
 * @notice Stake the staking token for the token to be paid as reward.
 */
function stake(address token, uint128 amount)
        external
        override
        nonReentrant
        updateTerm(token)
        updateReward(token, msg.sender)
    {
        if (_accountInfo[token][msg.sender].userTerm < _currentTerm[token]) {
            return;
        }

        require(amount != 0, "staking amount should be positive number");

        _updVoteAdd(msg.sender, amount);
        _stake(msg.sender, token, amount);
        _stakingToken.safeTransferFrom(msg.sender, address(this), amount);
    }
// Solidity 0.4.18
/// @dev Redistribute proceeds from token purchase
/// @param _tokenId Token ID of token to be purchased
/// @param _amount Amount paid into contract for token
function _distributeProceeds(uint256 _tokenId, uint256 _amount) private {
    uint256 fundsForDistribution = uint256(SafeMath.div(SafeMath.mul(_amount,
      distributionNumerator), distributionDenominator));
    uint256 commission = _amount;

    for (uint i = 0; i < tokenIndexToGroup[_tokenId].contributorArr.length; i++) {
      address userAdd = tokenIndexToGroup[_tokenId].contributorArr[i];

      // calculate contributor's sale proceeds and add to their withdrawable balance
      uint256 userProceeds = uint256(SafeMath.div(SafeMath.mul(fundsForDistribution,
        tokenIndexToGroup[_tokenId].addressToContribution[userAdd]),
        tokenIndexToGroup[_tokenId].contributedBalance));

      _clearGroupRecordInContributor(_tokenId, userAdd);

      // clear contributor record on group
      tokenIndexToGroup[_tokenId].addressToContribution[userAdd] = 0;
      tokenIndexToGroup[_tokenId].addressToContributorArrIndex[userAdd] = 0;

      commission -= userProceeds;
      userAddressToContributor[userAdd].withdrawableBalance += userProceeds;
      ProceedsDeposited(_tokenId, userAdd, userProceeds);
    }

    commissionBalance += commission;
    Commission(_tokenId, commission);

    activeGroups -= 1;
    tokenIndexToGroup[_tokenId].exists = false;
    tokenIndexToGroup[_tokenId].contributorArr.length = 0;
    tokenIndexToGroup[_tokenId].contributedBalance = 0;
    tokenIndexToGroup[_tokenId].purchasePrice = 0;
  }
// Solidity 0.4.18
/// @dev Calculates next price of celebrity token
/// @param _oldPrice Previous price
function _newPrice(uint256 _oldPrice) private view returns (uint256 newPrice) {
    if (_oldPrice < firstStepLimit) {
      // first stage
      newPrice = SafeMath.div(SafeMath.mul(_oldPrice, 200), 94);
    } else if (_oldPrice < secondStepLimit) {
      // second stage
      newPrice = SafeMath.div(SafeMath.mul(_oldPrice, 120), 94);
    } else {
      // third stage
      newPrice = SafeMath.div(SafeMath.mul(_oldPrice, 115), 94);
    }
  }
// Solidity 0.7.1
/**
 * @notice Withdraw the staking token for the token to be paid as reward.
 */
function withdraw(address token, uint128 amount)
        external
        override
        nonReentrant
        updateTerm(token)
        updateReward(token, msg.sender)
    {
        if (_accountInfo[token][msg.sender].userTerm < _currentTerm[token]) {
            return;
        }

        require(amount != 0, "withdrawing amount should be positive number");

        _updVoteSub(msg.sender, amount);
        _withdraw(msg.sender, token, amount);
        _stakingToken.safeTransfer(msg.sender, amount);
    }
// Solidity 0.7.1
/**
 * @notice Receive the reward for your staking in the token.
 */
function receiveReward(address token)
        external
        override
        nonReentrant
        updateTerm(token)
        updateReward(token, msg.sender)
        returns (uint256 rewards)
    {
        rewards = _accountInfo[token][msg.sender].rewards;
        if (rewards != 0) {
            _totalRemainingRewards[token] = _totalRemainingRewards[token].sub(rewards); // subtract the total unpaid reward
            _accountInfo[token][msg.sender].rewards = 0;
            if (token == ETH_ADDRESS) {
                _transferETH(msg.sender, rewards);
            } else {
                IERC20(token).safeTransfer(msg.sender, rewards);
            }
            emit RewardPaid(token, msg.sender, rewards);
        }
    }
// Solidity 0.6.12
//THE ONLY ADMIN FUNCTIONS ^^^^
function sqrt(uint y) public pure returns (uint z) {
        if (y > 3) {
            z = y;
            uint x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
    }
// Solidity 0.8.4
/// @notice Allots a new stake out of the stake of the message sender
/// @dev Stakeholder only may call
function splitStake(address newHolder, uint256 newAmount) external {
        address holder = msg.sender;
        require(newHolder != holder, "PStakes: duplicated address");

        Stake memory stake = _getStake(holder);
        require(newAmount <= stake.allocated, "PStakes: too large allocated");

        uint256 updAmount = uint256(stake.allocated) - newAmount;
        uint256 updReleased = (uint256(stake.released) * updAmount) /
            uint256(stake.allocated);
        stakes[holder] = Stake(_safe96(updAmount), _safe96(updReleased));
        emit StakeSplit(holder, updAmount, updReleased);

        uint256 newVested = uint256(stake.released) - updReleased;
        stakes[newHolder] = Stake(_safe96(newAmount), _safe96(newVested));
        emit StakeSplit(newHolder, newAmount, newVested);
    }
// Solidity 0.8.4
//////////////////
//// Owner ////
//////////////////
/// @notice Inits the contract and adds stakes
/// @dev Owner only may call on a proxy (but not on the implementation)
function addStakes(
        uint256 _poolId,
        address[] calldata holders,
        uint256[] calldata allocations,
        uint256 unallocated
    ) external onlyOwner {
        if (allocation == 0) {
            _init(_poolId);
        } else {
            require(_poolId == poolId, "PStakes: pool mismatch");
        }

        uint256 nEntries = holders.length;
        require(nEntries == allocations.length, "PStakes: length mismatch");
        uint256 updAllocated = uint256(allocated);
        for (uint256 i = 0; i < nEntries; i++) {
            _throwZeroHolderAddress(holders[i]);
            require(
                stakes[holders[i]].allocated == 0,
                "PStakes: holder exists"
            );
            require(allocations[i] > 0, "PStakes: zero allocation");

            updAllocated += allocations[i];
            stakes[holders[i]] = Stake(_safe96(allocations[i]), 0);
            emit StakeAdded(holders[i], allocations[i]);
        }
        require(
            updAllocated + unallocated == allocation,
            "PStakes: invalid allocation"
        );
        allocated = _safe96(updAllocated);
    }
// Solidity 0.8.4
/// @notice Withdraws accidentally sent token from this contract
/// @dev Owner may call only
function claimErc20(
        address claimedToken,
        address to,
        uint256 amount
    ) external onlyOwner nonReentrant {
        IERC20 vestedToken = IERC20(address(_getToken()));
        if (claimedToken == address(vestedToken)) {
            uint256 balance = vestedToken.balanceOf(address(this));
            require(
                balance - amount >= allocation - released,
                "PStakes: too big amount"
            );
        }
        _claimErc20(claimedToken, to, amount);
    }
// Solidity 0.8.4
/// @notice Removes the contract from blockchain when tokens are released
/// @dev Owner only may call on a proxy (but not on the implementation)
function removeContract() external onlyOwner {
        // avoid accidental removing of the implementation
        _throwImplementation();

        require(allocation == released, "PStakes: unpaid stakes");

        IERC20 vestedToken = IERC20(address(_getToken()));
        uint256 balance = vestedToken.balanceOf(address(this));
        require(balance == 0, "PStakes: non-zero balance");

        selfdestruct(payable(msg.sender));
    }
// Solidity 0.8.4
/// @notice Initialize the contract
/// @dev May be called on a proxy only (but not on the implementation)
function _init(uint256 _poolId) internal {
        _throwImplementation();
        require(_poolId < 2**16, "PStakes:unsafePoolId");

        IVestingPools pools = _getVestingPools();
        address wallet = pools.getWallet(_poolId);
        require(wallet == address(this), "PStakes:invalidPool");
        PoolParams memory pool = pools.getPool(_poolId);
        require(pool.sAllocation != 0, "PStakes:zeroPool");

        poolId = uint16(_poolId);
        allocation = _safe96(uint256(pool.sAllocation) * SCALE);
    }
// Solidity 0.8.4
/// @dev Returns amount that may be released for the given stake and factor
function _releasableAmount(Stake memory stake, uint256 _factor)
        internal
        pure
        returns (uint256)
    {
        uint256 share = (_factor * uint256(stake.allocated)) / SCALE;
        if (share > stake.allocated) {
            // imprecise division safeguard
            share = uint256(stake.allocated);
        }
        return share - uint256(stake.released);
    }
// Solidity 0.8.4
/// @dev Sends the releasable amount of the specified placeholder
function _withdraw(address holder) internal {
        Stake memory stake = _getStake(holder);
        uint256 releasable = _releasableAmount(stake, uint256(factor));
        require(releasable > 0, "PStakes: nothing to withdraw");

        stakes[holder].released = _safe96(uint256(stake.released) + releasable);
        released = _safe96(uint256(released) + releasable);

        // (reentrancy attack impossible - known contract called)
        require(_getToken().transfer(holder, releasable), "PStakes:E1");
        emit Released(holder, releasable);
    }
// Solidity 0.8.3
/// @dev Gets collateral balance deposited into Vesper Grow Pool
function _getCollateralBalance() internal view returns (uint256) {
        uint256 _totalSupply = vToken.totalSupply();
        // avoids division by zero error when pool is empty
        return (_totalSupply != 0) ? (vToken.totalValue() * vToken.balanceOf(address(this))) / _totalSupply : 0;
    }
// Solidity 0.5.16
// When we add a shortable pynth, we need to know the iPynth as well
// This is so we can get the proper skew for the short rate.
function addShortablePynths(bytes32[2][] calldata requiredPynthAndInverseNamesInResolver, bytes32[] calldata pynthKeys)
        external
        onlyOwner
    {
        require(requiredPynthAndInverseNamesInResolver.length == pynthKeys.length, "Input array length mismatch");

        for (uint i = 0; i < requiredPynthAndInverseNamesInResolver.length; i++) {
            // setting these explicitly for clarity
            // Each entry in the array is [Pynth, iPynth]
            bytes32 pynth = requiredPynthAndInverseNamesInResolver[i][0];
            bytes32 iPynth = requiredPynthAndInverseNamesInResolver[i][1];

            if (!_shortablePynths.contains(pynth)) {
                // Add it to the address set lib.
                _shortablePynths.add(pynth);

                // store the mapping to the iPynth so we can get its total supply for the borrow rate.
                pynthToInversePynth[pynth] = iPynth;

                emit ShortablePynthAdded(pynth);

                // now the associated pynth key to the CollateralManagerState
                state.addShortCurrency(pynthKeys[i]);
            }
        }

        rebuildCache();
    }
// Solidity 0.4.21
//A mapping to store the player pairs in private rooms based on keccak256 ids generated locally
//constructor
function Lottery() public{
        owner = msg.sender;
        player_count = 0;
        ante = 0.054 ether;
        required_number_players = 2;
        winner_percentage = 98;
        oraclize_setProof(proofType_Ledger); 
        oracle_price = 0.003 ether;
        oraclize_gas = 285000;
        private_rooms_index=0;
        paused = false;
        ticket_price = ante + oracle_price;
    }
// Solidity 0.4.21
// function when someone gambles a.k.a sends ether to the contract
function buy() whenNotPaused payable public{
        // No arguments are necessary, all
        // information is already part of
        // the transaction. The keyword payable
        // is required for the function to
        // be able to receive Ether.
    
        // If the bet is not equal to the ante + the oracle price, 
        // send the money back.
        require (msg.value >= ante + oracle_price);//give it back, revert state changes, abnormal stop
        require (player_count <2); //make sure that the counter was reset
        if(msg.value > (ante+oracle_price)) {
            msg.sender.transfer(msg.value - ante - oracle_price); //If any extra eteher gets transferred return it back to the sender
        }
         
        player_count +=1;
        if (player_count == 1) {
            players.player1 = msg.sender;
        }
        if (player_count == 2) {
            players.player2 = msg.sender;
            ShowPlayers (players.player1,players.player2);
            update();
            player_count =0;
        }
    }
// Solidity 0.4.14
/* Address => (productName => amount) */
function TestConf () { name = "TestConf"; totalSupply = 1000000; initialIssuance = totalSupply; owner = 0x443B9375536521127DBfABff21f770e4e684475d; currentEthPrice = 20000; /* TODO: Oracle */ currentTokenPrice = 100; /* In cents */ symbol = "TEST1"; balances[owner] = 100; }
// Solidity 0.8.4
/**
 * @dev Mint new quantity amount of nfts
 */
function mint(uint quantity) public payable isOpen notPaused {
    require(quantity > 0, "You can't mint 0");
    require(quantity <= maxPurchaseSize, "Exceeds max per transaction");
    require(totalSupply() + quantity <= MAX_SUPPLY, "Not enough token left");

    uint256 price = mintPrice.mul(quantity);
    require(msg.value >= price, "Value below order price");
    for(uint i = 0; i < quantity; i++){
        _safeMint(msg.sender, totalSupply().add(1));
    }

    uint256 remaining = msg.value.sub(price);
    if (remaining > 0) {
      (bool success, ) = msg.sender.call{value: remaining}("");
      require(success);
    }
  }
// Solidity 0.8.4
/**
 * @dev Returns all the token IDs owned by address who
 */
function tokensOfAddress(address who) external view returns(uint256[] memory) {
    uint tokenCount = balanceOf(who);
    uint256[] memory tokensId = new uint256[](tokenCount);
    for(uint i = 0; i < tokenCount; i++){
      tokensId[i] = tokenOfOwnerByIndex(who, i);
    }
    return tokensId;
  }
// Solidity 0.8.4
/**
 * @dev Mint new quantity amount of nfts for specific address
 * Bypass pause modifier
 */
function ownerMint(uint quantity) public ownersOnly {
    require(quantity > 0, "You can't mint 0");
    require(totalSupply() + quantity <= MAX_SUPPLY, "Not enough token left");
    for(uint i = 0; i < quantity; i++){
      _safeMint(msg.sender, totalSupply().add(1));
    }
  }
// Solidity 0.4.19
// Address of peg contract (to reject direct transfers)
function MinimalToken(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol,
        address _peg
        ) public {
        balances[msg.sender] = _initialAmount;
        totalSupply = _initialAmount;
        name = _tokenName;
        decimals = _decimalUnits;
        symbol = _tokenSymbol;
        peg = _peg;
    }