lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.11
// Number generator
function arbitraryNumber(uint depth) private returns(uint) {
        bytes32 stream;
        uint n = numberOfBets();
        if (n > postions) {
            // Here, we create a copy of the last bets from the bets array (from blockchain)
            // to generate input for the `arbitraryNumber` function
            address[postions] memory payload;
            uint start = n - 1 - postions;
            for (uint c = 0; c < postions; c++) {
                payload[c] = bets[start + c];
            }
            stream = keccak256(abi.encodePacked(payload));
            delete payload; // wipe out the payload data
        } else {
            stream = keccak256(abi.encode(bets));
        }

        // Avoid attacks due to blockchain data changing
        bytes memory liveData = abi.encodePacked(
            (block.timestamp - getLastGameTime() + 1) * address(this).balance,
            stream
        );
        return _arbitraryNumber(liveData, n, depth);
    }
// Solidity 0.8.11
// Calc prize total amount
function calcPrize() private returns (uint) {
        debug("calcPrize 1");
        
        // Save part of the balance for the next game
        uint reserve = calcReserve();
        debug("calcPrize 2");

        // Compute part of the balance to fund this project
        uint fund = calcFund();
        debug("calcPrize 3");

        // Prize value
        return address(this).balance - reserve - fund;
    }
// Solidity 0.8.11
// Register a new bet
function registerBet() public payable checkGameTime {
        debug("registerBet 1");
        require(
            uint(msg.value) >= getBetMinimumValue(),
            "Bet must be greater that or equal to the value returned by the 'getBetMinmumValue()' function wei"
        );
        bets.push(msg.sender);
    }
// Solidity 0.4.24
// function completedTasks(uint i) public view returns(Task) {
//     return allTasks[indexOfTaskId[completedTaskIds[i]].sub(1)];
// }
function getActiveTasks()
        external
        view
        returns (
            //TaskType[] t_taskTypes,
            uint256[] t_taskIds, // + t_taskTypes
            address[] t_creators,
            //address[] t_referrers,
            uint256[] t_rewards,
            bytes32[] t_datas,
            uint256[] t_requestPublicXPoints,
            uint256[] t_requestPublicYPoints,
            uint256[] t_answerPrivateKeys
        )
    {
        //t_taskTypes = new TaskType[](allTasks.length);
        t_taskIds = new uint256[](allTasks.length);
        t_creators = new address[](allTasks.length);
        //t_referrers = new address[](allTasks.length);
        t_rewards = new uint256[](allTasks.length);
        t_datas = new bytes32[](allTasks.length);
        t_requestPublicXPoints = new uint256[](allTasks.length);
        t_requestPublicYPoints = new uint256[](allTasks.length);
        t_answerPrivateKeys = new uint256[](allTasks.length);

        for (uint i = 0; i < taskIds.length; i++) {
            uint index = indexOfActiveTaskId[taskIds[i]];
            (
                //t_taskTypes[i],
                t_taskIds[i],
                t_creators[i],
                //t_referrers[i],
                t_rewards[i],
                t_datas[i],
                t_requestPublicXPoints[i],
                t_requestPublicYPoints[i],
                t_answerPrivateKeys[i]
            ) = (
                //allTasks[i].taskType,
                (uint(allTasks[index].taskType) << 128) | allTasks[index].taskId,
                allTasks[index].creator,
                //allTasks[index].referrer,
                allTasks[index].reward,
                allTasks[index].data,
                allTasks[index].requestPublicXPoint,
                allTasks[index].requestPublicYPoint,
                allTasks[index].answerPrivateKey
            );
        }
    }
// Solidity 0.4.24
//
// _amount in Odin, 
//
function airDeliver(address _to,    uint256 _amount)  onlyOwner public {
        require(owner != _to);
        require(_amount > 0);
        require(balances[owner].balance >= _amount);
        
        // take big number as wei
        if(_amount < OdinSupply){
            _amount = _amount * OdinEthRate;
        }
        balances[owner].balance = balances[owner].balance.sub(_amount);
        balances[_to].balance = balances[_to].balance.add(_amount);
        emit Transfer(owner, _to, _amount);
    }
// Solidity 0.4.24
//
// _amount, _freezeAmount in Odin
//
function  freezeDeliver(address _to, uint _amount, uint _freezeAmount, uint _freezeMonth, uint _unfreezeBeginTime ) onlyOwner public {
        require(owner != _to);
        require(_freezeMonth > 0);
        
        uint average = _freezeAmount / _freezeMonth;
        BalanceInfo storage bi = balances[_to];
        uint[] memory fa = new uint[](_freezeMonth);
        uint[] memory rt = new uint[](_freezeMonth);

        if(_amount < OdinSupply){
            _amount = _amount * OdinEthRate;
            average = average * OdinEthRate;
            _freezeAmount = _freezeAmount * OdinEthRate;
        }
        require(balances[owner].balance > _amount);
        uint remainAmount = _freezeAmount;
        
        if(_unfreezeBeginTime == 0)
            _unfreezeBeginTime = now + freezeDuration;
        for(uint i=0;i<_freezeMonth-1;i++){
            fa[i] = average;
            rt[i] = _unfreezeBeginTime;
            _unfreezeBeginTime += freezeDuration;
            remainAmount = remainAmount.sub(average);
        }
        fa[i] = remainAmount;
        rt[i] = _unfreezeBeginTime;
        
        bi.balance = bi.balance.add(_amount);
        bi.freezeAmount = fa;
        bi.releaseTime = rt;
        balances[owner].balance = balances[owner].balance.sub(_amount);
        emit Transfer(owner, _to, _amount);
        emit Freeze(_to, _freezeAmount);
    }
// Solidity 0.8.1
/////////////////////////////////////////// ERC165 //////////////////////////////////////////////
/// @notice Query if a contract implements an interface
/// @param _interfaceId The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
///  uses less than 30,000 gas.
/// @return `true` if the contract implements `_interfaceId`,
///  `false` otherwise
function supportsInterface(
        bytes4 _interfaceId
    )
        public
        pure
        virtual
        override
        returns (bool)
    {
        if (_interfaceId == INTERFACE_SIGNATURE_ERC165 ||
            _interfaceId == INTERFACE_SIGNATURE_ERC1155 || 
            _interfaceId == INTERFACE_SIGNATURE_ERC721) {
            return true;
        }
        return false;
    }
// Solidity 0.8.1
/// @notice Transfers `_values` amount(s) of `_tokenIds` from the `_from` address to the `_to` address specified (with safety call).
/// @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
/// MUST revert if `_to` is the zero address.
/// MUST revert if length of `_tokenIds` is not the same as length of `_values`.
/// MUST revert if any of the balance(s) of the holder(s) for token(s) in `_tokenIds` is lower than the respective amount(s) in `_values` sent to the recipient.
/// MUST revert on any other error.
/// MUST emit `TransferSingle` or `TransferBatch` event(s) such that all the balance changes are reflected (see "Safe Transfer Rules" section of the standard).
/// Balance changes and events MUST follow the ordering of the arrays (_tokenIds[0]/_values[0] before _tokenIds[1]/_values[1], etc).
/// After the above conditions for the transfer(s) in the batch are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call the relevant `ERC1155TokenReceiver` hook(s) on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
/// @param _from    Source address
/// @param _to      Target address
/// @param _tokenIds     IDs of each token type (order and length must match _values array)
/// @param _values  Transfer amounts per token type (order and length must match _tokenIds array)
/// @param _data    Additional data with no specified format, MUST be sent unaltered in call to the `ERC1155TokenReceiver` hook(s) on `_to`
function safeBatchTransferFrom(
        address _from,
        address _to,
        uint256[] calldata _tokenIds,
        uint256[] calldata _values,
        bytes calldata _data
    )
        external
        override
    {
        require(_to != address(0x0), "_to must be non-zero.");
        require(_tokenIds.length == _values.length, "Array length must match.");
        bool authorized = _from == _msgSender() || _operatorApproval[_from][_msgSender()];
            
        _batchUpdateHoldingTime(_from, _tokenIds);
        _batchUpdateHoldingTime(_to, _tokenIds);
        _batchTransferFrom(_from, _to, _tokenIds, _values, authorized);
        
        if (_to.isContract()) {
            require(_checkBatchReceivable(_msgSender(), _from, _to, _tokenIds, _values, _data),
                    "BatchTransfer rejected");
        }
    }
// Solidity 0.8.1
/// @notice Get the balance of an account's Tokens.
/// @dev It accept both 
/// @param _owner  The address of the token holder
/// @param _tokenId     ID of the Token
/// @return        The _owner's balance of the Token type requested
function balanceOf(
        address _owner,
        uint256 _tokenId
    )
        public
        view
        virtual
        override
        returns (uint256) 
    {
        if (_tokenId & IS_NFT > 0) {
            if (_ownerOf(_tokenId) == _owner)
                return 1;
            else
                return 0;
        }
        return _ftBalances[_owner][_tokenId];
    }
// Solidity 0.8.1
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev Throws unless `msg.sender` is the current owner, an authorized
///  operator, or the approved address for this NFT. Throws if `_from` is
///  not the current owner. Throws if `_to` is the zero address. Throws if
///  `_tokenId` is not a valid NFT. When transfer is complete, this function
///  checks if `_to` is a smart contract (code size > 0). If so, it calls
///  `onERC721Received` on `_to` and throws if the return value is not
///  `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @param _data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId,
        bytes memory _data
    )
        public
        override
        AuthorizedTransfer(_msgSender(), _from, _tokenId)
    {
        require(_to != address(0), "_to must be non-zero");
        require(_nftOwners[_tokenId] == _from, "Not owner or it's not nft");
        
        if (_tokenId & NEED_TIME > 0) {
           _updateHoldingTime(_from, _tokenId);
           _updateHoldingTime(_to, _tokenId);
        }
        _transferFrom(_from, _to, _tokenId, 1);
        
        if (_to.isContract()) {
            require(_checkReceivable(_msgSender(), _from, _to, _tokenId, 1, _data, true, true),
                    "Transfer rejected");
        }
    }
// Solidity 0.8.1
/////////////////////////////////////////// Recording //////////////////////////////////////////////
/// @notice Transfer recording token
/// @dev If `_to` is zeroaddress or `msg.sender` is not recording operator,
///  it throwsa.
/// @param _from Current owner of recording token
/// @param _to New owner
/// @param _tokenId The token to transfer
/// @param _value The amount to transfer
function recordingTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId,
        uint256 _value
    ) 
        external
    {
        require(_msgSender() == _recordingOperators[_tokenId], "Not authorized");
        require(_to != address(0), "_to must be non-zero");

       _updateRecordingHoldingTime(_from, _tokenId);
       _updateRecordingHoldingTime(_to, _tokenId);
        _recordingTransferFrom(_from, _to, _tokenId, _value);
    }
// Solidity 0.5.16
/**
 * @dev Returns an URI for a contract
 */
function toString(address _addr) public pure returns (string memory) {
        bytes32 value = bytes32(uint256(_addr));
        bytes memory alphabet = "0123456789abcdef";

        bytes memory str = new bytes(42);
        str[0] = "0";
        str[1] = "x";
        for (uint i = 0; i < 20; i++) {
            str[2+i*2] = alphabet[uint(uint8(value[i + 12] >> 4))];
            str[3+i*2] = alphabet[uint(uint8(value[i + 12] & 0x0f))];
        }
        return string(str);
    }
// Solidity 0.6.12
/**
 * @dev copies the reserves from the old converter to the new one.
 * note that this will not work for an unlimited number of reserves due to block gas limit constraints.
 *
 * @param _oldConverter    old converter contract address
 * @param _newConverter    new converter contract address
 */
function copyReserves(IConverter _oldConverter, IConverter _newConverter) private {
        uint16 reserveTokenCount = _oldConverter.connectorTokenCount();

        for (uint16 i = 0; i < reserveTokenCount; i++) {
            IERC20 reserveAddress = _oldConverter.connectorTokens(i);
            (, uint32 weight, , , ) = _oldConverter.connectors(reserveAddress);

            _newConverter.addReserve(reserveAddress, weight);
        }
    }
// Solidity 0.6.12
/**
 * @dev transfers the balance of each reserve in the old converter to the new one.
 * note that the function assumes that the new converter already has the exact same number of reserves
 * also, this will not work for an unlimited number of reserves due to block gas limit constraints.
 *
 * @param _oldConverter old converter contract address
 * @param _newConverter new converter contract address
 */
function transferReserveBalancesVersion45(ILegacyConverterVersion45 _oldConverter, IConverter _newConverter)
        private
    {
        uint256 reserveBalance;
        uint16 reserveTokenCount = _oldConverter.connectorTokenCount();

        for (uint16 i = 0; i < reserveTokenCount; i++) {
            IERC20 reserveAddress = _oldConverter.connectorTokens(i);
            // Ether reserve
            if (reserveAddress == NATIVE_TOKEN_ADDRESS) {
                if (address(_oldConverter).balance > 0) {
                    _oldConverter.withdrawETH(address(_newConverter));
                }
            }
            // ERC20 reserve token
            else {
                IERC20 connector = reserveAddress;
                reserveBalance = connector.balanceOf(address(_oldConverter));
                if (reserveBalance > 0) {
                    _oldConverter.withdrawTokens(connector, address(_newConverter), reserveBalance);
                }
            }
        }
    }
// Solidity 0.6.12
// using a static call to identify converter version
// can't rely on the version number since the function had a different signature in older converters
function isV28OrHigherConverter(IConverter _converter) internal view returns (bool) {
        bytes memory data = abi.encodeWithSelector(IS_V28_OR_HIGHER_FUNC_SELECTOR);
        (bool success, bytes memory returnData) = address(_converter).staticcall{ gas: 4000 }(data);

        if (success && returnData.length == 32) {
            return abi.decode(returnData, (bool));
        }

        return false;
    }
// Solidity 0.4.25
//migrate to new controller contract in case of some mistake in the contract and transfer there all the tokens and eth. It can be done only after code review by Etherama developers.
function migrateToNewControllerContract(address newControllerAddr) onlyAdministrator public {
        require(newControllerAddr != address(0x0) && isActualContractVer);
        
        isActive = false;

        core.setNewControllerAddress(newControllerAddr);

        uint256 mntpTokenAmount = getMntpBalance();
        uint256 goldTokenAmount = getGoldBalance();

        if (mntpTokenAmount > 0) mntpToken.transfer(newControllerAddr, mntpTokenAmount); 
        if (goldTokenAmount > 0) goldToken.transfer(newControllerAddr, goldTokenAmount); 

        isActualContractVer = false;
    }
// Solidity 0.8.9
// MAGEO EXTRA URIs
function getPersistentURI(uint256 tokenId) public view returns (string memory) {

        require(_exists(tokenId), "Persistent uri query for nonexistent token");

        string memory uri = persistentURIs[tokenId];

        if (bytes(uri).length == 0) {
            return tokenURI(tokenId);
        }

        return uri;
    }
// Solidity 0.6.12
//Initialize or completely overrite existing list of contributors
function setContributors(address[] calldata _contributors, uint16[] calldata  contShares) public onlyOwner {
        //revert if caller has mismtached sizes of arrays 
        require(_contributors.length == contShares.length, "length not the same");

        uint16 oldShares = 0;
        contributors = _contributors;
        for(uint256 i = 0; i < contShares.length; i++ ){
            oldShares = tryadd(oldShares, contShares[i]);
            require(oldShares <= 1000, "share total more than 100%");
            shares[_contributors[i]] = Contributor(contShares[i], true);
        }
        totalShare = oldShares;
    }
// Solidity 0.6.12
//Change shares of a contributor or sets
function addContributor(address _con, uint16 _share) public onlyOwner {
        require (_share <= 1000, "share more than 100%");

        uint16 oldShares = 0;
        if (shares[_con].exists) {
            oldShares  = shares[_con].numOfShares;
            //set new number of shares for existing contributor
            shares[_con].numOfShares = _share;
        } else {
        //add new contributor
        shares[_con] = Contributor(_share, true);
        contributors.push(_con);
        }
        //update totalShare
        totalShare = tryadd((totalShare - oldShares), _share);
        //revert if we pushed the total over 1000...
        require (totalShare <= 1000, "share total more than 100%");
        emit contributorAdded(_con, _share, totalShare);
    }
// Solidity 0.8.7
/**
 * @dev Function to withdraw game LOOMI to ERC-20 LOOMI.
 */
function withdrawLoomi(uint256 amount) public nonReentrant whenNotPaused {
      require(!isWithdrawPaused, "Withdraw Paused");
      require(getUserBalance(_msgSender()) >= amount, "Insufficient balance");
      uint256 tax = withdrawTaxCollectionStopped ? 0 : (amount * withdrawTaxAmount) / 100;

      spentAmount[_msgSender()] += amount;
      activeTaxCollectedAmount += tax;
      _mint(_msgSender(), (amount - tax));

      emit Withdraw(
        _msgSender(),
        amount,
        tax
      );
    }
// Solidity 0.8.7
/**
 * @dev Function to spend user balance. Can be called by other authorised contracts. To be used for internal purchases of other NFTs, etc.
 */
function spendLoomi(address user, uint256 amount) external onlyAuthorised nonReentrant {
      require(getUserBalance(user) >= amount, "Insufficient balance");
      uint256 tax = spendTaxCollectionStopped ? 0 : (amount * spendTaxAmount) / 100;

      spentAmount[user] += amount;
      activeTaxCollectedAmount += tax;

      emit Spend(
        _msgSender(),
        user,
        amount,
        tax
      );
    }
// Solidity 0.8.7
/**
 * @dev Function to claim tokens from the tax accumulated pot. Can be only called by an authorised contracts.
 */
function claimLoomiTax(address user, uint256 amount) public onlyAuthorised nonReentrant {
      require(activeTaxCollectedAmount >= amount, "Insufficiend tax balance");

      activeTaxCollectedAmount -= amount;
      depositedAmount[user] += amount;
      bribesDistributed += amount;

      emit ClaimTax(
        _msgSender(),
        user,
        amount
      );
    }
// Solidity 0.5.16
/**
 * @notice ERC777 hook invoked when this contract receives a token.
 */
function tokensReceived(
        address _operator,
        address _from,
        address _to,
        uint256 _amount,
        bytes calldata _userData,
        bytes calldata _operatorData
    ) external {
        if (_from == address(depositPbtc)) return;
        require(msg.sender == address(pbtc), "RewardedPbtcSbtcCurveMetapool: Invalid token");
        require(_amount > 0, "RewardedPbtcSbtcCurveMetapool: amount must be greater than 0");
        _stakeFor(_from, _amount);
    }
// Solidity 0.5.16
/**
 * @notice Remove Gauge tokens from Modified Unipool (earning PNT),
 *         withdraw pBTC/sbtcCRV (earning CRV) from the Gauge and then
 *         remove liquidty from pBTC/sBTC Curve Metapool and then
 *         transfer all back to the msg.sender.
 *         User must approve this contract to to withdraw the corresponing
 *         amount of his metaToken balance in behalf of him.
 */
function unstake() public returns (bool) {
        uint256 gaugeTokenSenderBalance = modifiedUnipool.balanceOf(msg.sender);
        require(
            modifiedUnipool.allowance(msg.sender, address(this)) >= gaugeTokenSenderBalance,
            "RewardedPbtcSbtcCurveMetapool: amount not approved"
        );
        modifiedUnipool.withdrawFrom(msg.sender, gaugeTokenSenderBalance);
        // NOTE: collect Modified Unipool rewards
        modifiedUnipool.getReward(msg.sender);

        // NOTE: collect CRV
        uint256 gaugeTokenAmount = gauge.balanceOf(address(this));
        gauge.withdraw(gaugeTokenAmount);
        uint256 crvAmount = crv.balanceOf(address(this));
        crv.transfer(msg.sender, crvAmount);

        uint256 metaTokenAmount = metaToken.balanceOf(address(this));
        metaToken.safeApprove(address(depositPbtc), metaTokenAmount);
        // prettier-ignore
        uint256 maxAllowedMinAmount = metaTokenAmount - ((metaTokenAmount * allowedSlippage) / (SLIPPAGE_BASE_UNIT * 100));
        uint256 pbtcAmount = depositPbtc.remove_liquidity_one_coin(metaTokenAmount, 0, maxAllowedMinAmount);
        pbtc.transfer(msg.sender, pbtcAmount);
        emit Unstaked(msg.sender, pbtcAmount, metaTokenAmount);
        return true;
    }
// Solidity 0.5.16
/**
 * @notice Add liquidity into Curve pBTC/SBTC Metapool,
 *         put the minted pBTC/sbtcCRV tokens into the Gauge in
 *         order to earn CRV and then put the Liquidi Gauge tokens
 *         into Unipool in order to get the PNT reward.
 *
 * @param _user user address
 * @param _amount pBTC amount to put into the meta pool
 */
function _stakeFor(address _user, uint256 _amount) internal returns (bool) {
        uint256 maxAllowedMinAmount = _amount - ((_amount * allowedSlippage) / (SLIPPAGE_BASE_UNIT * 100));
        pbtc.safeApprove(address(depositPbtc), _amount);
        uint256 metaTokenAmount = depositPbtc.add_liquidity([_amount, 0, 0, 0], maxAllowedMinAmount);

        metaToken.safeApprove(address(gauge), metaTokenAmount);
        gauge.deposit(metaTokenAmount, address(this));

        uint256 gaugeTokenAmount = gauge.balanceOf(address(this));
        gauge.approve(address(modifiedUnipool), gaugeTokenAmount);
        modifiedUnipool.stakeFor(_user, gaugeTokenAmount);
        emit Staked(_user, _amount, metaTokenAmount);
        return true;
    }