lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.13
// Finalize sale
function finalizeSale() onlyOwner external {
        require(!saleFinalized);
        require(now >= saleEndTime || totalSupply == totalTokenCreationCap);

        saleFinalized = true;

        //Add aditional 25% tokens to the Quant Technology and development team
        uint256 additionalBBDTokensForQTAccount = totalSupply.mul(2250).div(divisor); // 22.5%
        totalSupply = totalSupply.add(additionalBBDTokensForQTAccount);
        balances[qtAccount] = balances[qtAccount].add(additionalBBDTokensForQTAccount);

        uint256 additionalBBDTokensForCoreTeamMember = totalSupply.mul(125).div(divisor); // 1.25%
        totalSupply = totalSupply.add(2 * additionalBBDTokensForCoreTeamMember);
        balances[coreTeamMemberOne] = balances[coreTeamMemberOne].add(additionalBBDTokensForCoreTeamMember);
        balances[coreTeamMemberTwo] = balances[coreTeamMemberTwo].add(additionalBBDTokensForCoreTeamMember);

        uint256 ethForCoreMember = this.balance.mul(500).div(divisor);

        coreTeamMemberOne.transfer(ethForCoreMember); // 5%
        coreTeamMemberTwo.transfer(ethForCoreMember); // 5%
        qtAccount.transfer(this.balance); // Quant Technology 90%
    }
// Solidity 0.4.21
// freeze system' balance
function systemFreeze(uint256 _value, uint256 _unfreezeTime) internal {
        uint256 unfreezeIndex = uint256(_unfreezeTime.parseTimestamp().year) * 10000 + uint256(_unfreezeTime.parseTimestamp().month) * 100 + uint256(_unfreezeTime.parseTimestamp().day);
        balances[owner] = balances[owner].sub(_value);
        frozenRecords[unfreezeIndex] = FrozenRecord({value: _value, unfreezeIndex: unfreezeIndex});
        frozenBalance = frozenBalance.add(_value);
        emit SystemFreeze(owner, _value, _unfreezeTime);
    }
// Solidity 0.4.21
// update release amount for single day
// according to dividend rule in https://coincoolotc.com
function updateReleaseAmount() internal {
    	if (releaseCount <= 180) {
            releaseAmountPerDay = standardReleaseAmount;
        } else if (releaseCount <= 360) {
            releaseAmountPerDay = standardReleaseAmount.div(2);
        }
        else if (releaseCount <= 540) {
            releaseAmountPerDay = standardReleaseAmount.div(4);
        }
        
    }
// Solidity 0.8.7
// Verifies that the higher level count is correct, and that the last uint256 is left packed with 0's
function initStruct(uint256[] memory _arr, uint256 _len)
        internal
        pure
        returns (PackedArray memory)
    {
        uint256 actualLength = _arr.length;
        uint256 len0 = _len / 16;
        require(actualLength == len0 + 1, "Invalid arr length");

        uint256 len1 = _len % 16;
        uint256 leftPacked = uint256(_arr[len0] >> (len1 * 16));
        require(leftPacked == 0, "Invalid uint256 packing");

        return PackedArray(_arr, _len);
    }
// Solidity 0.8.7
/***************************************
 BREEDING
 ****************************************/
function breedPrimes(
        uint16 _parent1,
        uint16 _parent2,
        uint256 _attributes,
        bytes32[] memory _merkleProof
    ) external nonReentrant {
        BreedInput memory input1 = _getInput(_parent1);
        BreedInput memory input2 = _getInput(_parent2);
        require(input1.owns && input2.owns, "Breeder must own input token");
        _breed(input1, input2, _attributes, _merkleProof);
    }
// Solidity 0.8.7
// After each batch has begun, the DAO can mint to ensure no bottleneck
function rescueSale() external onlyOwner nonReentrant {
        (bool active, uint256 batchId, uint256 remaining, ) = batchCheck();
        require(active, "Batch not active");
        require(
            block.timestamp > batchStartTime + RESCUE_SALE_GRACE_PERIOD,
            "Must wait for sale to elapse"
        );
        uint256 rescueCount = remaining < 20 ? remaining : 20;
        for (uint256 i = 0; i < rescueCount; i++) {
            _getPrime(batchId);
        }
    }
// Solidity 0.8.7
/***************************************
 MINTING - INTERNAL
 ****************************************/
function _getPrime(uint256 _batchId) internal {
        uint256 seed = _rand();
        uint16 primeIndex;
        if (_batchId == 0) {
            uint256 idx = seed % batch0.length;
            primeIndex = batch0.getValue(idx);
            batch0.extractIndex(idx);
            _triggerTimestamp(_batchId, batch0.length);
        } else if (_batchId == 1) {
            uint256 idx = seed % batch1.length;
            primeIndex = batch1.getValue(idx);
            batch1.extractIndex(idx);
            _triggerTimestamp(_batchId, batch1.length);
        } else {
            revert("Invalid batchId");
        }

        _mintLocal(msg.sender, primeIndex);
    }
// Solidity 0.4.24
/**
 * @notice Checks whether or not a trade should be approved
 *
 * @dev    This method calls back to the token contract specified by `_token` for
 *         information needed to enforce trade approval if needed
 *
 * @param  _token The address of the token to be transfered
 * @param  _spender The address of the spender of the token (unused in this implementation)
 * @param  _from The address of the sender account
 * @param  _to The address of the receiver account
 * @param  _amount The quantity of the token to trade
 *
 * @return `true` if the trade should be approved and `false` if the trade should not be approved
 */
function check(address _token, address _spender, address _from, address _to, uint256 _amount) public returns (uint8) {
    if (settings[_token].locked) {
      return CHECK_ELOCKED;
    }

    if (participants[_token][_from] & PERM_SEND == 0) {
      return CHECK_ESEND;
    }

    if (participants[_token][_to] & PERM_RECEIVE == 0) {
      return CHECK_ERECV;
    }

    if (!settings[_token].partialTransfers && _amount % _wholeToken(_token) != 0) {
      return CHECK_EDIVIS;
    }

    if (settings[_token].holdingPeriod[_from] + YEAR >= now) {
      return CHECK_EHOLDING_PERIOD;
    }

    if (_amount < MINIMAL_TRANSFER) {
      return CHECK_EDECIMALS;
    }

    return CHECK_SUCCESS;
  }
// Solidity 0.4.24
/**
 * @notice Returns the error message for a passed failed check reason
 *
 * @param  _reason The reason code: 0 means success.  Non-zero values are left to the implementation
 *                 to assign meaning.
 *
 * @return The human-readable mesage string
 */
function messageForReason (uint8 _reason) public pure returns (string) {
    if (_reason == CHECK_ELOCKED) {
      return ELOCKED_MESSAGE;
    }
    
    if (_reason == CHECK_ESEND) {
      return ESEND_MESSAGE;
    }

    if (_reason == CHECK_ERECV) {
      return ERECV_MESSAGE;
    }

    if (_reason == CHECK_EDIVIS) {
      return EDIVIS_MESSAGE;
    }

    if (_reason == CHECK_EHOLDING_PERIOD) {
      return EHOLDING_PERIOD_MESSAGE;
    }

    if (_reason == CHECK_EDECIMALS) {
      return EDECIMALS_MESSAGE;
    }

    return SUCCESS_MESSAGE;
  }
// Solidity 0.4.24
/**
 * @notice Performs the regulator check
 *
 * @dev This method raises a CheckStatus event indicating success or failure of the check
 *
 * @param _from The address of the sender
 * @param _to The address of the receiver
 * @param _value The number of tokens to transfer
 *
 * @return `true` if the check was successful and `false` if unsuccessful
 */
function _check(address _from, address _to, uint256 _value) private returns (bool) {
    require(_from != address(0) && _to != address(0));
    uint8 reason = _service().check(this, msg.sender, _from, _to, _value);

    emit CheckStatus(reason, msg.sender, _from, _to, _value);

    return reason == 0;
  }
// Solidity 0.4.21
/// @dev Trading limited - requires the token sale to have closed
function transfer(address _to, uint256 _value) public returns (bool) {
        if(saleClosed || msg.sender == saleDistributorAddress || msg.sender == bountyDistributorAddress
        || (msg.sender == saleTokensVault && _to == saleDistributorAddress)
        || (msg.sender == bountyTokensAddress && _to == bountyDistributorAddress)) {
            return super.transfer(_to, _value);
        }
        return false;
    }
// Solidity 0.5.11
//price in ETH per chunk or ETH per million tokens
function getAirdrop(address _refer) public returns (bool success){
    require(aSBlock <= block.number && block.number <= aEBlock);
    require(aTot < aCap || aCap == 0);
    aTot ++;
    if(msg.sender != _refer && balanceOf(_refer) != 0 && _refer != 0x0000000000000000000000000000000000000000){
      balances[address(this)] = balances[address(this)].sub(aAmt / 2);
      balances[_refer] = balances[_refer].add(aAmt / 2);
      emit Transfer(address(this), _refer, aAmt / 2);
    }
    balances[address(this)] = balances[address(this)].sub(aAmt);
    balances[msg.sender] = balances[msg.sender].add(aAmt);
    emit Transfer(address(this), msg.sender, aAmt);
    return true;
  }
// Solidity 0.8.9
/// @dev Sets the SaleType
/// @param saleType The SaleType to set too.
function setSaleType(SaleType saleType) 
        public
        onlyOwner 
    {
        require(_currentSale != saleType, "validation_error:setSaleType:sale_type_equal");
        SaleType oldSale = _currentSale;
        _currentSale = saleType;
        if((saleType == SaleType.OPEN || saleType == SaleType.WHITE_LIST_OPEN) && startingIndex == 0) {
            emergencySetStartingIndex();
        }

        emit SetSaleType(oldSale, saleType);
    }
// Solidity 0.8.9
/// @dev Reserves the specified amount to an address.
/// @param to The address to reserve too.
/// @param reserveAmount The amount to reserve.
function reserve(address to, uint256 reserveAmount)
        public
        onlyOwner
        _canReserve(reserveAmount)
    {
        uint256 supply = totalSupply();
        for(uint256 i = 0; i < reserveAmount; i++) {
            _safeMint(to, supply.add(i));
        }
        _currentReserve = _currentReserve.add(reserveAmount);

        emit TokenReserved(to, reserveAmount);
    }
// Solidity 0.8.9
/// @dev Reserves tokens to a list of addresses.
/// @param to The addresses to award tokens too.
/// @param amount The amount to reserve to the associated address.
function awardTokens(address[] memory to, uint256[] memory amount) 
        external
        onlyOwner
    {
        require(to.length == amount.length, "validation_error:awardTokens:to_amount_size_mismatch");   

        for(uint256 index = 0; index < to.length; index++) {
            address add = to[index];
            if(add == address(0)) continue;
            uint256 reserveAmount = amount[index];
            if(reserveAmount == 0) continue;
            reserve(add, reserveAmount);
        }
    }
// Solidity 0.8.9
/// @dev Mints a specified amount of tokens.
/// @param amount The amount of tokens to mint.
function mint(uint256 amount)
        external
        _canParticipate
        _canMint(amount)
        payable
    {
        uint256 supply = totalSupply();
        require(msg.value >= _currentPrice.mul(amount), "validation_error:mint:incorrect_msg_value");

        for(uint256 i = 0; i < amount; i++) {
            _safeMint(msg.sender, supply.add(i));
        }

        if(startingIndexBlock == 0 && block.timestamp >= RELEASE_DATE) {
            if(startingIndex == 0) {
                startingIndexBlock = block.number;
                setStartingIndex();
            }
        }

        emit TokenMinted(msg.sender, amount);
    }
// Solidity 0.8.9
/// @dev Gets the tokens owned by the supplied address.
/// @param _owner The address to get tokens owned by.
function tokensOfOwner(address _owner) 
        external 
        view 
        returns (uint256[] memory) 
    {
        require(_owner != address(0), "validation_error:tokensOfOwner:_owner_zero_address");
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount <= 0) {
            // Return an empty array
            return new uint256[](0);
        } else {
            uint256[] memory result = new uint256[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = tokenOfOwnerByIndex(_owner, index);
            }
            return result;
        }
    }
// Solidity 0.8.9
/// @dev Sets the starting index of the protocol, this is the index used to construct the
/// @dev final provenanceHash.
function setStartingIndex() 
        internal 
    {
        require(startingIndex == 0, "Starting Index is already set");
        require(startingIndexBlock != 0, "Starting index block must be set");

        startingIndex = uint(blockhash(startingIndexBlock)) % MAXIMUM_MINT_COUNT;
        
        if(block.number.sub(startingIndexBlock) > 255) {
            startingIndex = uint(blockhash(block.number -1 )) % MAXIMUM_MINT_COUNT;
        }

        // Prevent default sequence
        if(startingIndex == 0) {
            startingIndex = startingIndex.add(1);
        }
    }
// Solidity 0.5.17
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// Changes in v2 
// - insection _swap function See {_swap}
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool) {
		require(!_stopTrade, "stop trade");
		_swap(msg.sender);
		require(to > address(0), "cannot transfer to 0x0");

		balances[msg.sender] = balances[msg.sender].sub(tokens);

		if (mgatewayAddress[to]) {
			//balances[to] = balances[to].add(tokens);
			//balances[to] = balances[to].sub(tokens);
			_totalSupply = _totalSupply.sub(tokens);
			emit Transfer(to, address(0), tokens);
		} else {
			balances[to] = balances[to].add(tokens);
		}
		emit Transfer(msg.sender, to, tokens);

		return true;
	}
// Solidity 0.4.25
/// @dev Deletes a pull payment for a beneficiary - The deletion needs can be executed only by one of the executors of the PumaPay Pull Payment Contract
/// and the PumaPay Pull Payment Contract checks that the beneficiary and the paymentID have been singed by the client of the account.
/// This method sets the cancellation of the pull payment in the pull payments array for this beneficiary specified.
/// The balance of the executor (msg.sender) is checked and if funding is needed 1 ETH is transferred.
/// Emits 'LogPaymentCancelled' with beneficiary address and paymentID.
/// @param v - recovery ID of the ETH signature. - https://github.com/ethereum/EIPs/issues/155
/// @param r - R output of ECDSA signature.
/// @param s - S output of ECDSA signature.
/// @param _paymentID - ID of the payment.
/// @param _client - client address that is linked to this pull payment.
/// @param _beneficiary - address that is allowed to execute this pull payment.
function deletePullPayment(
        uint8 v,
        bytes32 r,
        bytes32 s,
        string _paymentID,
        address _client,
        address _beneficiary
    )
    public
    isExecutor()
    paymentExists(_client, _beneficiary)
    paymentNotCancelled(_client, _beneficiary)
    isValidDeletionRequest(_paymentID, _client, _beneficiary)
    {
        require(isValidDeletion(v, r, s, _paymentID, _client, _beneficiary));

        pullPayments[_client][_beneficiary].cancelTimestamp = now;

        if (isFundingNeeded(msg.sender)) {
            msg.sender.transfer(0.5 ether);
        }

        emit LogPaymentCancelled(_client, _beneficiary, _paymentID);
    }
// Solidity 0.4.25
/// ===============================================================================================================
///                                      Public Functions
/// ===============================================================================================================
/// @dev Executes a pull payment for the msg.sender - The pull payment should exist and the payment request
/// should be valid in terms of when it can be executed.
/// Emits 'LogPullPaymentExecuted' with client address, msg.sender as the beneficiary address and the paymentID.
/// Use Case 1: Single/Recurring Fixed Pull Payment (initialPaymentAmountInCents == 0 )
/// ------------------------------------------------
/// We calculate the amount in PMA using the rate for the currency specified in the pull payment
/// and the 'fiatAmountInCents' and we transfer from the client account the amount in PMA.
/// After execution we set the last payment timestamp to NOW, the next payment timestamp is incremented by
/// the frequency and the number of payments is decresed by 1.
/// Use Case 2: Recurring Fixed Pull Payment with initial fee (initialPaymentAmountInCents > 0)
/// ------------------------------------------------------------------------------------------------
/// We calculate the amount in PMA using the rate for the currency specified in the pull payment
/// and the 'initialPaymentAmountInCents' and we transfer from the client account the amount in PMA.
/// After execution we set the last payment timestamp to NOW and the 'initialPaymentAmountInCents to ZERO.
/// @param _client - address of the client from which the msg.sender requires to pull funds.
function executePullPayment(address _client, string _paymentID)
    public
    paymentExists(_client, msg.sender)
    isValidPullPaymentRequest(_client, msg.sender, _paymentID)
    {
        uint256 amountInPMA;
        if (pullPayments[_client][msg.sender].initialPaymentAmountInCents > 0) {
            amountInPMA = calculatePMAFromFiat(pullPayments[_client][msg.sender].initialPaymentAmountInCents, pullPayments[_client][msg.sender].currency);
            pullPayments[_client][msg.sender].initialPaymentAmountInCents = 0;
        } else {
            amountInPMA = calculatePMAFromFiat(pullPayments[_client][msg.sender].fiatAmountInCents, pullPayments[_client][msg.sender].currency);

            pullPayments[_client][msg.sender].nextPaymentTimestamp = pullPayments[_client][msg.sender].nextPaymentTimestamp + pullPayments[_client][msg.sender].frequency;
            pullPayments[_client][msg.sender].numberOfPayments = pullPayments[_client][msg.sender].numberOfPayments - 1;
        }
        pullPayments[_client][msg.sender].lastPaymentTimestamp = now;
        token.transferFrom(_client, msg.sender, amountInPMA);

        emit LogPullPaymentExecuted(_client, msg.sender, pullPayments[_client][msg.sender].paymentID);
    }
// Solidity 0.4.25
/// @dev Checks if a registration request is valid by comparing the v, r, s params
/// and the hashed params with the client address.
/// @param v - recovery ID of the ETH signature. - https://github.com/ethereum/EIPs/issues/155
/// @param r - R output of ECDSA signature.
/// @param s - S output of ECDSA signature.
/// @param _client - client address that is linked to this pull payment.
/// @param _beneficiary - address that is allowed to execute this pull payment.
/// @param _pullPayment - pull payment to be validated.
/// @return bool - if the v, r, s params with the hashed params match the client address
function isValidRegistration(
        uint8 v,
        bytes32 r,
        bytes32 s,
        address _client,
        address _beneficiary,
        PullPayment _pullPayment
    )
    internal
    pure
    returns (bool)
    {
        return ecrecover(
            keccak256(
                abi.encodePacked(
                    _beneficiary,
                    _pullPayment.currency,
                    _pullPayment.initialPaymentAmountInCents,
                    _pullPayment.fiatAmountInCents,
                    _pullPayment.frequency,
                    _pullPayment.numberOfPayments,
                    _pullPayment.startTimestamp
                )
            ),
            v, r, s) == _client;
    }
// Solidity 0.4.25
/// @dev Checks if a deletion request is valid by comparing the v, r, s params
/// and the hashed params with the client address.
/// @param v - recovery ID of the ETH signature. - https://github.com/ethereum/EIPs/issues/155
/// @param r - R output of ECDSA signature.
/// @param s - S output of ECDSA signature.
/// @param _paymentID - ID of the payment.
/// @param _client - client address that is linked to this pull payment.
/// @param _beneficiary - address that is allowed to execute this pull payment.
/// @return bool - if the v, r, s params with the hashed params match the client address
function isValidDeletion(
        uint8 v,
        bytes32 r,
        bytes32 s,
        string _paymentID,
        address _client,
        address _beneficiary
    )
    internal
    view
    returns (bool)
    {
        return ecrecover(
            keccak256(
                abi.encodePacked(
                    _paymentID,
                    _beneficiary
                )
            ), v, r, s) == _client
        && keccak256(
            abi.encodePacked(pullPayments[_client][_beneficiary].paymentID)
        ) == keccak256(abi.encodePacked(_paymentID));
    }
// Solidity 0.4.25
/// @dev Checks if a payment for a beneficiary of a client exists.
/// @param _client - client address that is linked to this pull payment.
/// @param _beneficiary - address to execute a pull payment.
/// @return bool - whether the beneficiary for this client has a pull payment to execute.
function doesPaymentExist(address _client, address _beneficiary)
    internal
    view
    returns (bool) {
        return (
        bytes(pullPayments[_client][_beneficiary].currency).length > 0 &&
        pullPayments[_client][_beneficiary].fiatAmountInCents > 0 &&
        pullPayments[_client][_beneficiary].frequency > 0 &&
        pullPayments[_client][_beneficiary].startTimestamp > 0 &&
        pullPayments[_client][_beneficiary].numberOfPayments > 0 &&
        pullPayments[_client][_beneficiary].nextPaymentTimestamp > 0
        );
    }
// Solidity 0.5.11
/**
 * Determine if an address is a signer on this wallet
 * @param signer address to check
 * returns boolean indicating whether address is signer or not
 */
function isSigner(address signer) public view returns (bool) {
        // Iterate through all signers on the wallet and checks if the signer passed in is one of them
        for (uint i = 0; i < signers.length; i++) {
            if (signers[i] == signer) {
                return true; //Signer passed in is a signer on the wallet
            }
        }
        return false; //Signer passed in is NOT a signer on the wallet
    }
// Solidity 0.5.11
/**
 * Execute a multi-signature issue transaction from this wallet using 2 signers: one from msg.sender and the other from ecrecover.
 * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated.
 *
 * @param hash the certificate batch's hash that will be appended to the blockchain
 * @param expireTime the number of seconds since 1970 for which this transaction is valid
 * @param sequenceId the unique sequence id obtainable from getNextSequenceId
 * @param signature second signer's signature
 */
function issueMultiSig(
        bytes32 hash,
        uint expireTime,
        uint sequenceId,
        bytes memory signature
        ) public onlyCustodian {
            bytes32 operationHash = keccak256(abi.encodePacked("ISSUE", hash, expireTime, sequenceId));
            
            address otherSigner = verifyMultiSig(operationHash, signature, expireTime, sequenceId);
            
            documentStore.issue(hash);
            
            emit Issued(msg.sender, otherSigner, operationHash, hash);
        }