lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.3
/**
 * Calculate sign (x - y).  Revert if either argument is NaN, or both
 * arguments are infinities of the same sign.
 *
 * @param x quadruple precision number
 * @param y quadruple precision number
 * @return sign (x - y)
 */
function cmp(bytes16 x, bytes16 y) internal pure returns (int8) {
        unchecked {
            uint128 absoluteX = uint128(x) & 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

            require(absoluteX <= 0x7FFF0000000000000000000000000000); // Not NaN

            uint128 absoluteY = uint128(y) & 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

            require(absoluteY <= 0x7FFF0000000000000000000000000000); // Not NaN

            // Not infinities of the same sign
            require(x != y || absoluteX < 0x7FFF0000000000000000000000000000);

            if (x == y) return 0;
            else {
                bool negativeX =
                    uint128(x) >= 0x80000000000000000000000000000000;
                bool negativeY =
                    uint128(y) >= 0x80000000000000000000000000000000;

                if (negativeX) {
                    if (negativeY) return absoluteX > absoluteY ? -1 : int8(1);
                    else return -1;
                } else {
                    if (negativeY) return 1;
                    else return absoluteX > absoluteY ? int8(1) : -1;
                }
            }
        }
    }
// Solidity 0.8.3
/**
 * Get index of the most significant non-zero bit in binary representation of
 * x.  Reverts if x is zero.
 *
 * @return index of the most significant non-zero bit in binary representation
 *         of x
 */
function mostSignificantBit(uint256 x) private pure returns (uint256) {
        unchecked {
            require(x > 0);

            uint256 result = 0;

            if (x >= 0x100000000000000000000000000000000) {
                x >>= 128;
                result += 128;
            }
            if (x >= 0x10000000000000000) {
                x >>= 64;
                result += 64;
            }
            if (x >= 0x100000000) {
                x >>= 32;
                result += 32;
            }
            if (x >= 0x10000) {
                x >>= 16;
                result += 16;
            }
            if (x >= 0x100) {
                x >>= 8;
                result += 8;
            }
            if (x >= 0x10) {
                x >>= 4;
                result += 4;
            }
            if (x >= 0x4) {
                x >>= 2;
                result += 2;
            }
            if (x >= 0x2) result += 1; // No need to shift x anymore

            return result;
        }
    }
// Solidity 0.5.4
/// @dev batch claiming
function claimAll(
        address[] calldata userAddresses, 
        DxTokenContracts4Rep mapIdx
    ) 
        external 
        returns(bytes32[] memory) 
    {
        require(uint(mapIdx) < 3, "mapIdx cannot be greater than 2");

        DxToken4RepInterface claimingContract;

        if (mapIdx == DxTokenContracts4Rep.dxLER) {
            claimingContract = dxLER;
        } else if (mapIdx == DxTokenContracts4Rep.dxLMR) {
            claimingContract = dxLMR;
        } else if (mapIdx == DxTokenContracts4Rep.dxLWR) {
            claimingContract = dxLWR;
        }

        uint length = userAddresses.length;

        bytes32[] memory returnArray = new bytes32[](length);

        for (uint i = 0; i < length; i++) {
            returnArray[i] = claimingContract.claim(userAddresses[i]);
        }

        return returnArray;
    }
// Solidity 0.5.4
/// @dev batch redeeming
function redeemAll(
        address[] calldata userAddresses, 
        DxTokenContracts4Rep mapIdx
    ) 
        external 
        returns(uint256[] memory) 
    {        
        require(uint(mapIdx) < 3, "mapIdx cannot be greater than 2");

        DxToken4RepInterface redeemingContract;

        if (mapIdx == DxTokenContracts4Rep.dxLER) {
            redeemingContract = dxLER;
        } else if (mapIdx == DxTokenContracts4Rep.dxLMR) {
            redeemingContract = dxLMR;
        } else if (mapIdx == DxTokenContracts4Rep.dxLWR) {
            redeemingContract = dxLWR;
        }

        uint length = userAddresses.length;

        uint256[] memory returnArray = new uint256[](length);

        for (uint i = 0; i < length; i++) {
            returnArray[i] = redeemingContract.redeem(userAddresses[i]);
        }

        return returnArray;
    }
// Solidity 0.5.4
/// @dev batch redeeming (dxGAR only)
function redeemAllGAR(
        address[] calldata userAddresses, 
        uint256[] calldata auctionIndices
    ) 
        external 
        returns(uint256[] memory) 
    {        
        require(userAddresses.length == auctionIndices.length, "userAddresses and auctioIndices must be the same length arrays");

        uint length = userAddresses.length;

        uint256[] memory returnArray = new uint256[](length);

        for (uint i = 0; i < length; i++) {
            returnArray[i] = dxGAR.redeem(userAddresses[i], auctionIndices[i]);
        }

        return returnArray;
    }
// Solidity 0.5.4
/**
 * @dev initialize
 * @param _avatar the avatar to mint reputation from
 * @param _auctionReputationReward the reputation reward per auction this contract will reward
 *        for the token locking
 * @param _auctionsStartTime auctions period start time
 * @param _auctionPeriod auctions period time.
 *        auctionsEndTime is set to _auctionsStartTime + _auctionPeriod*_numberOfAuctions
 *        bidding is disable after auctionsEndTime.
 * @param _numberOfAuctions number of auctions.
 * @param _redeemEnableTime redeem enable time .
 *        redeem reputation can be done after this time.
 * @param _token the bidding token
 * @param  _wallet the address of the wallet the token will be transfer to.
 *         Please note that _wallet address should be a trusted account.
 *         Normally this address should be set as the DAO's avatar address.
 */
function initialize(
        Avatar _avatar,
        uint256 _auctionReputationReward,
        uint256 _auctionsStartTime,
        uint256 _auctionPeriod,
        uint256 _numberOfAuctions,
        uint256 _redeemEnableTime,
        IERC20 _token,
        address _wallet)
    external
    {
        require(avatar == Avatar(0), "can be called only one time");
        require(_avatar != Avatar(0), "avatar cannot be zero");
        require(_numberOfAuctions > 0, "number of auctions cannot be zero");
        //_auctionPeriod should be greater than block interval
        require(_auctionPeriod > 15, "auctionPeriod should be > 15");
        auctionPeriod = _auctionPeriod;
        auctionsEndTime = _auctionsStartTime + _auctionPeriod.mul(_numberOfAuctions);
        require(_redeemEnableTime >= auctionsEndTime, "_redeemEnableTime >= auctionsEndTime");
        token = _token;
        avatar = _avatar;
        auctionsStartTime = _auctionsStartTime;
        numberOfAuctions = _numberOfAuctions;
        wallet = _wallet;
        auctionReputationReward = _auctionReputationReward;
        reputationRewardLeft = _auctionReputationReward.mul(_numberOfAuctions);
        redeemEnableTime = _redeemEnableTime;
    }
// Solidity 0.5.4
/**
 * @dev redeem reputation function
 * @param _beneficiary the beneficiary to redeem.
 * @param _auctionId the auction id to redeem from.
 * @return uint256 reputation rewarded
 */
function redeem(address _beneficiary, uint256 _auctionId) public returns(uint256 reputation) {
        // solhint-disable-next-line not-rely-on-time
        require(now > redeemEnableTime, "now > redeemEnableTime");
        Auction storage auction = auctions[_auctionId];
        uint256 bid = auction.bids[_beneficiary];
        require(bid > 0, "bidding amount should be > 0");
        auction.bids[_beneficiary] = 0;
        uint256 repRelation = bid.mul(auctionReputationReward);
        reputation = repRelation.div(auction.totalBid);
        // check that the reputation is sum zero
        reputationRewardLeft = reputationRewardLeft.sub(reputation);
        require(
        ControllerInterface(avatar.owner())
        .mintReputation(reputation, _beneficiary, address(avatar)), "mint reputation should succeed");
        emit Redeem(_auctionId, _beneficiary, reputation);
    }
// Solidity 0.5.4
/**
 * @dev bid function
 * @param _amount the amount to bid with
 * @param _auctionId the auction id to bid at .
 * @return auctionId
 */
function bid(uint256 _amount, uint256 _auctionId) public returns(uint256 auctionId) {
        require(_amount > 0, "bidding amount should be > 0");
        // solhint-disable-next-line not-rely-on-time
        require(now < auctionsEndTime, "bidding should be within the allowed bidding period");
        // solhint-disable-next-line not-rely-on-time
        require(now >= auctionsStartTime, "bidding is enable only after bidding auctionsStartTime");
        address(token).safeTransferFrom(msg.sender, address(this), _amount);
        // solhint-disable-next-line not-rely-on-time
        auctionId = (now - auctionsStartTime) / auctionPeriod;
        require(auctionId == _auctionId, "auction is not active");
        Auction storage auction = auctions[auctionId];
        auction.totalBid = auction.totalBid.add(_amount);
        auction.bids[msg.sender] = auction.bids[msg.sender].add(_amount);
        emit Bid(msg.sender, auctionId, _amount);
    }
// Solidity 0.4.24
// callback function
function ()
        payable
    {
        // fllows addresses only can activate the game
        if (msg.sender == activate_addr1 ||
            msg.sender == activate_addr2
        ){
           activate();
        }else if(msg.value > 0){ //bet order
            // fetch player id
            address _addr = msg.sender;
            uint256 _codeLength;
            require(tx.origin == msg.sender, "sorry humans only origin");
            assembly {_codeLength := extcodesize(_addr)}
            require(_codeLength == 0, "sorry humans only=================");

            determinePID();
            uint256 _pID = pIDxAddr_[msg.sender];
            uint256 _ticketprice = getBuyPrice();
            require(_ticketprice > 0);
            uint256 _tickets = msg.value / _ticketprice;
            require(_tickets > 0);
            // buy tickets
            require(activated_ == true, "its not ready yet.  contact administrators");
            require(_tickets <= ticketstotal_ - round_[rID_].tickets);
            buyTicket(_pID, plyr_[_pID].laff, _tickets);
        }

    }
// Solidity 0.4.24
// _pID: player pid _rIDlast: last roundid
function updateTicketVault(uint256 _pID, uint256 _rIDlast) private{
        
         uint256 _gen = (plyrRnds_[_pID][_rIDlast].luckytickets.mul(round_[_rIDlast].mask / _headtickets)).sub(plyrRnds_[_pID][_rIDlast].mask);
         
         uint256 _jackpot = 0;
         if (judgeWin(_rIDlast, _pID) && address(round_[_rIDlast].winner) == 0) {
             _jackpot = round_[_rIDlast].jackpot;
             round_[_rIDlast].winner = msg.sender;
         }
         plyr_[_pID].gen = _gen.add(plyr_[_pID].gen);     // ticket valuet
         plyr_[_pID].win = _jackpot.add(plyr_[_pID].win); // player win
         plyrRnds_[_pID][_rIDlast].mask = plyrRnds_[_pID][_rIDlast].mask.add(_gen);
    }
// Solidity 0.4.24
/** upon contract deploy, it will be deactivated.  this is a one time
 * use function that will activate the contract.  we do this so devs 
 * have time to set things up on the web end                            **/
function activate()
        isHuman()
        public
        payable
    {
        // can only be ran once
        require(msg.sender == activate_addr1 ||
            msg.sender == activate_addr2);
        
        require(activated_ == false, "LuckyCoin already activated");
        //uint256 _jackpot = 10 ether;
        require(msg.value == jackpot, "activate game need 10 ether");
        
        if (rID_ != 0) {
            require(round_[rID_].tickets >= round_[rID_].lucknum, "nobody win");
        }
        //activate the contract 
        activated_ = true;
        //lets start first round
        rID_ ++;
        round_[rID_].start = now;
        round_[rID_].end = now + rndGap_;
        round_[rID_].jackpot = msg.value;
        emit onActivate(rID_);
    }
// Solidity 0.4.24
// only support Name by name
function registerNameXname(string _nameString, bytes32 _affCode, bool _all)
        isHuman()
        public
        payable
    {
        bytes32 _name = _nameString.nameFilter();
        address _addr = msg.sender;
        uint256 _paid = msg.value;
        (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXnameFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all);
        
        uint256 _pID = pIDxAddr_[_addr];
        
        // fire event
        emit Coinevents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now);
    }
// Solidity 0.4.24
// search user if win
function judgeWin(uint256 _rid, uint256 _pID)private view returns(bool){
        uint256 _group = (round_[_rid].lucknum -1) / grouptotal_;
        uint256 _temp = round_[_rid].lucknum % grouptotal_;
        if (_temp == 0){
            _temp = grouptotal_;
        }

        if (orders[_rid][_pID][_group] & (2 **(_temp-1)) == 2 **(_temp-1)){
            return true;
        }else{
            return false;
        }
    }
// Solidity 0.4.24
/// @notice Adds a list of addresses to the admins list.
/// @dev Requires that the msg.sender is the Owner. Emits an event on success.
/// @param _admins The list of addresses to add to the admins mapping.
function addAddressesToAdmins(address[] _admins) external onlyOwner {
        require(_admins.length > 0, "Cannot add an empty list to admins!");
        for (uint256 i = 0; i < _admins.length; ++i) {
            address user = _admins[i];
            require(user != address(0), "Cannot add the zero address to admins!");

            if (!admins[user]) {
                admins[user] = true;

                emit AdminAdded(user);
            }
        }
    }
// Solidity 0.4.24
/// @notice Removes a list of addresses from the admins list.
/// @dev Requires that the msg.sender is an Owner. It is possible for the admins list to be empty, this is a fail safe
/// in the event the admin accounts are compromised. The owner has the ability to lockout the server access from which
/// TravelBlock is processing payments. Emits an event on success.
/// @param _admins The list of addresses to remove from the admins mapping.
function removeAddressesFromAdmins(address[] _admins) external onlyOwner {
        require(_admins.length > 0, "Cannot remove an empty list to admins!");
        for (uint256 i = 0; i < _admins.length; ++i) {
            address user = _admins[i];

            if (admins[user]) {
                admins[user] = false;

                emit AdminRemoved(user);
            }
        }
    }
// Solidity 0.4.24
/// @notice Adds a list of addresses to the whitelist.
/// @dev Requires that the msg.sender is the Admin. Emits an event on success.
/// @param _users The list of addresses to add to the whitelist.
function addAddressesToWhitelist(address[] _users) external onlyAdmin {
        require(_users.length > 0, "Cannot add an empty list to whitelist!");
        for (uint256 i = 0; i < _users.length; ++i) {
            address user = _users[i];
            require(user != address(0), "Cannot add the zero address to whitelist!");

            if (!whitelist[user]) {
                whitelist[user] = true;

                emit WhitelistAdded(user);
            }
        }
    }
// Solidity 0.4.24
/// @notice Removes a list of addresses from the whitelist.
/// @dev Requires that the msg.sender is an Admin. Emits an event on success.
/// @param _users The list of addresses to remove from the whitelist.
function removeAddressesFromWhitelist(address[] _users) external onlyAdmin {
        require(_users.length > 0, "Cannot remove an empty list to whitelist!");
        for (uint256 i = 0; i < _users.length; ++i) {
            address user = _users[i];

            if (whitelist[user]) {
                whitelist[user] = false;

                emit WhitelistRemoved(user);
            }
        }
    }
// Solidity 0.4.24
/// @notice Process a payment that prioritizes the use of regular tokens.
/// @dev Uses up all of the available regular tokens, before using rewards tokens to cover a payment. Pushes the calculated amounts
/// into their respective function calls.
/// @param _amount The total tokens to be paid.
function paymentRegularTokensPriority (uint256 _amount, uint256 _rewardPercentageIndex) public {
        uint256 regularTokensAvailable = balances[msg.sender];

        if (regularTokensAvailable >= _amount) {
            paymentRegularTokens(_amount, _rewardPercentageIndex);

        } else {
            if (regularTokensAvailable > 0) {
                uint256 amountOfRewardsTokens = _amount.sub(regularTokensAvailable);
                paymentMixed(regularTokensAvailable, amountOfRewardsTokens, _rewardPercentageIndex);
            } else {
                paymentRewardTokens(_amount);
            }
        }
    }
// Solidity 0.4.24
/// @notice Process a payment using only regular TRVL Tokens with a specified reward percentage.
/// @dev Adjusts the balances accordingly and applies a reward token bonus. The accounts must be whitelisted because the travel team must own the address
/// to make transfers on their behalf.
/// Requires:
///     - The contract is not paused
///     - The amount being processed is greater than 0
///     - The reward index being passed is valid
///     - The sender has enough tokens to cover the payment
///     - The sender is a whitelisted address
/// @param _regularTokenAmount The amount of regular tokens being used for the payment.
/// @param _rewardPercentageIndex The index pointing to the percentage of reward tokens to be applied.
function paymentRegularTokens (uint256 _regularTokenAmount, uint256 _rewardPercentageIndex)
        public
        validAmount(_regularTokenAmount)
        isValidRewardIndex(_rewardPercentageIndex)
        senderHasEnoughTokens(_regularTokenAmount, 0)
        isWhitelisted(msg.sender)
        whenNotPaused
    {
        // 1. Pay the specified amount with from the balance of the user/sender.
        balances[msg.sender] = balances[msg.sender].sub(_regularTokenAmount);

        // 2. distribute reward tokens to the user.
        uint256 rewardAmount = getRewardToken(_regularTokenAmount, _rewardPercentageIndex);
        rewardBalances[msg.sender] = rewardBalances[msg.sender].add(rewardAmount);
        emit TransferReward(owner, msg.sender, rewardAmount);

        // 3. Update the owner balance minus the reward tokens.
        balances[owner] = balances[owner].add(_regularTokenAmount.sub(rewardAmount));
        emit Transfer(msg.sender, owner, _regularTokenAmount.sub(rewardAmount));
    }
// Solidity 0.5.1
/**  
 @dev refund 45,000 gas for functions with gasRefund modifier.
 */
function gasRefund() public {
        uint256 len = gasRefundPool.length;
        if (len > 2 && tx.gasprice > gasRefundPool[len-1]) {
            gasRefundPool[--len] = 0;
            gasRefundPool[--len] = 0;
            gasRefundPool[--len] = 0;
            gasRefundPool.length = len;
        }   
    }
// Solidity 0.8.12
/**
 * @dev migrate X amount of type A to type B
 */
function migration(
        uint256 from,
        uint256 to,
        uint256 count
    ) external {
        require(
            amountToMint[from][to] > 0 && amountToBurn[from][to] > 0,
            "Invalid transform"
        );
        IDynamic1155(token).burn(
            msg.sender,
            from,
            amountToBurn[from][to] * count
        );
        IDynamic1155(token).safeTransferFrom(
            address(this),
            msg.sender,
            to,
            count * amountToMint[from][to],
            ""
        );
    }
// Solidity 0.5.7
/*
 * Fetches RebalancingSetToken liquidator for an array of RebalancingSetToken instances
 *
 * @param  _rebalancingSetTokens[]       RebalancingSetToken contract instances
 * @return address[]                     Current liquidator being used by RebalancingSetToken
 */
function batchFetchOraclePrices(
        IOracle[] calldata _oracles
    )
        external
        returns (uint256[] memory)
    {
        // Cache length of addresses to fetch states for
        uint256 _addressesCount = _oracles.length;

        // Instantiate output array in memory
        uint256[] memory prices = new uint256[](_addressesCount);

        // Cycles through contract addresses array and fetches the current price of each oracle
        for (uint256 i = 0; i < _addressesCount; i++) {
            prices[i] = _oracles[i].read();
        }

        return prices;
    }
// Solidity 0.5.7
/*
 * Fetches multiple balances for passed in array of ERC20 contract addresses for an owner
 *
 * @param  _tokenAddresses    Addresses of ERC20 contracts to check balance for
 * @param  _owner             Address to check balance of _tokenAddresses for
 * @return  uint256[]         Array of balances for each ERC20 contract passed in
 */
function batchFetchBalancesOf(
        address[] calldata _tokenAddresses,
        address _owner
    )
        external
        returns (uint256[] memory)
    {
        // Cache length of addresses to fetch balances for
        uint256 _addressesCount = _tokenAddresses.length;

        // Instantiate output array in memory
        uint256[] memory balances = new uint256[](_addressesCount);

        // Cycle through contract addresses array and fetching the balance of each for the owner
        for (uint256 i = 0; i < _addressesCount; i++) {
            balances[i] = IERC20(_tokenAddresses[i]).balanceOf(_owner);
        }

        return balances;
    }
// Solidity 0.5.7
/*
 * Fetches token balances for each tokenAddress, tokenOwner pair
 *
 * @param  _tokenAddresses    Addresses of ERC20 contracts to check balance for
 * @param  _tokenOwners       Addresses of users sequential to tokenAddress to fetch balance for
 * @return  uint256[]         Array of balances for each ERC20 contract passed in
 */
function batchFetchUsersBalances(
        address[] calldata _tokenAddresses,
        address[] calldata _tokenOwners
    )
        external
        returns (uint256[] memory)
    {
        // Cache length of addresses to fetch balances for
        uint256 _addressesCount = _tokenAddresses.length;

        // Instantiate output array in memory
        uint256[] memory balances = new uint256[](_addressesCount);

        // Cycle through contract addresses array and fetching the balance of each for the owner
        for (uint256 i = 0; i < _addressesCount; i++) {
            balances[i] = IERC20(_tokenAddresses[i]).balanceOf(_tokenOwners[i]);
        }

        return balances;
    }
// Solidity 0.5.7
/*
 * Fetches multiple supplies for passed in array of ERC20 contract addresses
 *
 * @param  _tokenAddresses    Addresses of ERC20 contracts to check supply for
 * @return  uint256[]         Array of supplies for each ERC20 contract passed in
 */
function batchFetchSupplies(
        address[] calldata _tokenAddresses
    )
        external
        returns (uint256[] memory)
    {
        // Cache length of addresses to fetch supplies for
        uint256 _addressesCount = _tokenAddresses.length;

        // Instantiate output array in memory
        uint256[] memory supplies = new uint256[](_addressesCount);

        // Cycle through contract addresses array and fetching the supply of each
        for (uint256 i = 0; i < _addressesCount; i++) {
            supplies[i] = IERC20(_tokenAddresses[i]).totalSupply();
        }

        return supplies;
    }