lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.13
/**
 * @dev mint rewardToken for financial opportunity
 *
 * For valid finOp, deposit Token into finOp
 * Update finOpSupply & finOpBalance for account
 * Emit mintRewardToken event on success
 *
 * @param account account to mint rewardToken for
 * @param amount amount of depositToken to mint
 * @param finOp financial opportunity address
 */
function mintRewardToken(
        address account,
        uint256 amount,
        address finOp
    ) internal validFinOp(finOp) returns (uint256) {
        // require sufficient balance
        require(super.balanceOf(account) >= amount, "insufficient token balance");

        // approve finOp can spend Token
        _setAllowance(account, finOp, amount);

        // deposit into finOp
        uint256 rewardAmount = _getFinOp(finOp).deposit(account, amount);

        // increase finOp rewardToken supply
        finOpSupply[finOp] = finOpSupply[finOp].add(rewardAmount);

        // increase account rewardToken balance
        _addRewardBalance(account, rewardAmount, finOp);

        // emit mint event
        emit MintRewardToken(account, amount, finOp);

        return rewardAmount;
    }
// Solidity 0.5.13
/**
 * @dev redeem rewardToken balance for depositToken
 *
 * For valid finOp, deposit Token into finOp
 * Update finOpSupply & finOpBalance for account
 * Emit mintRewardToken event on success
 *
 * @param account account to redeem rewardToken for
 * @param amount depositToken amount to redeem
 * @param finOp financial opportunitu address
 */
function redeemRewardToken(
        address account,
        uint256 amount,
        address finOp
    ) internal validFinOp(finOp) returns (uint256) {
        // require sufficient balance
        require(rewardTokenBalance(account, finOp) >= amount, "insufficient reward balance");

        // withdraw from finOp, giving TUSD to account
        uint256 tokenAmount = _getFinOp(finOp).redeem(account, amount);

        // decrease finOp rewardToken supply
        finOpSupply[finOp] = finOpSupply[finOp].sub(amount);

        // decrease account rewardToken balance
        _subRewardBalance(account, amount, finOp);

        // emit mint event
        emit RedeemRewardToken(account, tokenAmount, finOp);

        return tokenAmount;
    }
// Solidity 0.5.13
/**
 * @dev burn rewardToken without redeeming
 *
 * Burn rewardToken for finOp
 *
 * @param account account to burn rewardToken for
 * @param amount depositToken amount to burn
 * @param finOp financial opportunity address
 */
function burnRewardToken(
        address account,
        uint256 amount,
        address finOp
    )
        internal
        validFinOp(finOp)
    {
        // burn call must come from sender
        require(msg.sender == account);

        // sender must have rewardToken amount to burn
        require(rewardTokenBalance(account, finOp) >= amount);

        // subtract reward balance from
        _subRewardBalance(account, amount, finOp);

        // reduce total supply
        finOpSupply[finOp].sub(amount);

        // burn event
        emit BurnRewardToken(account, amount, finOp);
    }
// Solidity 0.4.15
// ignore the Crowdsale.rate and dynamically compute rate based on other factors (e.g. purchase amount, time, etc)
function FlipCrowdsale(MintableToken _token, uint256 _startTime, uint256 _endTime, address _ethWallet)
    Ownable()
    Pausable()
    Contactable()
    HasNoTokens()
    HasNoContracts()
    Crowdsale(_startTime, _endTime, 1, _ethWallet)
    FinalizableCrowdsale()
    {
        // deployment must set token.owner = FlipCrowdsale.address to allow minting
        token = _token;
        contactInformation = 'https://tokensale.gameflip.com/';
    }
// Solidity 0.4.15
// over-ridden low level token purchase function so that we
// can control the token-per-wei exchange rate dynamically
function buyTokens(address beneficiary) public payable whenNotPaused {
        require(beneficiary != 0x0);
        require(validPurchase());

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = applyExchangeRate(weiAmount);

        // update state
        weiRaised = weiRaised.add(weiAmount);
        tokensSold = tokensSold.add(tokens);

        token.mint(beneficiary, tokens);
        TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

        forwardFunds();
    }
// Solidity 0.4.15
/**
 * @dev Can be overridden to add finalization logic. The overriding function
 * should call super.finalization() to ensure the chain of finalization is
 * executed entirely.
 */
function finalization() internal {
        // if we own the token, pass ownership to our owner when finalized
        if(address(token) != address(0) && token.owner() == address(this) && owner != address(0)) {
            token.transferOwnership(owner);
        }
        super.finalization();
    }
// Solidity 0.8.10
/**
 * @dev Associate a document with the token.
 * @param name Short name (represented as a bytes32) associated to the document.
 * @param uri Document content.
 * @param documentHash Hash of the document [optional parameter].
 */
function setDocument(bytes32 name, string calldata uri, bytes32 documentHash) external override {
    require(_isController[msg.sender]);
    _documents[name] = Doc({
      docURI: uri,
      docHash: documentHash,
      timestamp: block.timestamp
    });

    if (_indexOfDocHashes[documentHash] == 0) {
      _docHashes.push(documentHash);
      _indexOfDocHashes[documentHash] = _docHashes.length;
    }

    emit DocumentUpdated(name, uri, documentHash);
  }
// Solidity 0.8.10
/**
 * @dev Transfer the amount of tokens on behalf of the address 'from' to the address 'to'.
 * @param from Token holder (or 'address(0)' to set from to 'msg.sender').
 * @param to Token recipient.
 * @param value Number of tokens to transfer.
 * @param data Information attached to the transfer, and intended for the token holder ('from').
 */
function transferFromWithData(address from, address to, uint256 value, bytes calldata data) external override virtual {
    require( _isOperator(msg.sender, from)
      || (value <= _allowed[from][msg.sender]), "53"); // 0x53	insufficient allowance

    if(_allowed[from][msg.sender] >= value) {
      _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
    } else {
      _allowed[from][msg.sender] = 0;
    }

    _transferByDefaultPartitions(msg.sender, from, to, value, data);
  }
// Solidity 0.8.10
/**
 * @dev Transfer tokens from a specific partition through an operator.
 * @param partition Name of the partition.
 * @param from Token holder.
 * @param to Token recipient.
 * @param value Number of tokens to transfer.
 * @param data Information attached to the transfer. [CAN CONTAIN THE DESTINATION PARTITION]
 * @param operatorData Information attached to the transfer, by the operator.
 * @return Destination partition.
 */
function operatorTransferByPartition(
    bytes32 partition,
    address from,
    address to,
    uint256 value,
    bytes calldata data,
    bytes calldata operatorData
  )
    external
    override
    returns (bytes32)
  {
    //We want to check if the msg.sender is an authorized operator for `from`
    //(msg.sender == from OR msg.sender is authorized by from OR msg.sender is a controller if this token is controlable)
    //OR
    //We want to check if msg.sender is an `allowed` operator/spender for `from`
    require(_isOperatorForPartition(partition, msg.sender, from)
      || (value <= _allowedByPartition[partition][from][msg.sender]), "53"); // 0x53	insufficient allowance

    if(_allowedByPartition[partition][from][msg.sender] >= value) {
      _allowedByPartition[partition][from][msg.sender] = _allowedByPartition[partition][from][msg.sender].sub(value);
    } else {
      _allowedByPartition[partition][from][msg.sender] = 0;
    }

    return _transferByPartition(partition, msg.sender, from, to, value, data, operatorData);
  }
// Solidity 0.8.10
/**
 * @dev Redeem the amount of tokens on behalf of the address from.
 * @param from Token holder whose tokens will be redeemed (or address(0) to set from to msg.sender).
 * @param value Number of tokens to redeem.
 * @param data Information attached to the redemption.
 */
function redeemFrom(address from, uint256 value, bytes calldata data)
    external
    override
    virtual
  {
    require(_isOperator(msg.sender, from)
      || (value <= _allowed[from][msg.sender]), "53"); // 0x53	insufficient allowance

    if(_allowed[from][msg.sender] >= value) {
      _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
    } else {
      _allowed[from][msg.sender] = 0;
    }

    _redeemByDefaultPartitions(msg.sender, from, value, data);
  }
// Solidity 0.8.10
/**
 * @dev Redeem tokens of a specific partition.
 * @param partition Name of the partition.
 * @param tokenHolder Address for which we want to redeem tokens.
 * @param value Number of tokens redeemed
 * @param operatorData Information attached to the redemption, by the operator.
 */
function operatorRedeemByPartition(bytes32 partition, address tokenHolder, uint256 value, bytes calldata operatorData)
    external
    override
  {
    require(_isOperatorForPartition(partition, msg.sender, tokenHolder) || value <= _allowedByPartition[partition][tokenHolder][msg.sender], "58"); // 0x58	invalid operator (transfer agent)

    if(_allowedByPartition[partition][tokenHolder][msg.sender] >= value) {
      _allowedByPartition[partition][tokenHolder][msg.sender] = _allowedByPartition[partition][tokenHolder][msg.sender].sub(value);
    } else {
      _allowedByPartition[partition][tokenHolder][msg.sender] = 0;
    }

    _redeemByPartition(partition, msg.sender, tokenHolder, value, "", operatorData);
  }
// Solidity 0.8.10
/**
 * @dev Perform the transfer of tokens.
 * @param from Token holder.
 * @param to Token recipient.
 * @param value Number of tokens to transfer.
 */
function _transferWithData(
    address from,
    address to,
    uint256 value
  )
    internal
    isNotMigratedToken
  {
    require(_isMultiple(value), "50"); // 0x50	transfer failure
    require(to != address(0), "57"); // 0x57	invalid receiver
    require(_balances[from] >= value, "52"); // 0x52	insufficient balance
  
    _balances[from] = _balances[from].sub(value);
    _balances[to] = _balances[to].add(value);

    emit Transfer(from, to, value); // ERC20 retrocompatibility 
  }
// Solidity 0.8.10
/**
 * @dev Transfer tokens from default partitions.
 * Function used for ERC20 retrocompatibility.
 * @param operator The address performing the transfer.
 * @param from Token holder.
 * @param to Token recipient.
 * @param value Number of tokens to transfer.
 * @param data Information attached to the transfer, and intended for the token holder ('from') [CAN CONTAIN THE DESTINATION PARTITION].
 */
function _transferByDefaultPartitions(
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data
  )
    internal
  {
    require(_defaultPartitions.length != 0, "55"); // // 0x55	funds locked (lockup period)

    uint256 _remainingValue = value;
    uint256 _localBalance;

    for (uint i = 0; i < _defaultPartitions.length; i++) {
      _localBalance = _balanceOfByPartition[from][_defaultPartitions[i]];
      if(_remainingValue <= _localBalance) {
        _transferByPartition(_defaultPartitions[i], operator, from, to, _remainingValue, data, "");
        _remainingValue = 0;
        break;
      } else if (_localBalance != 0) {
        _transferByPartition(_defaultPartitions[i], operator, from, to, _localBalance, data, "");
        _remainingValue = _remainingValue - _localBalance;
      }
    }

    require(_remainingValue == 0, "52"); // 0x52	insufficient balance
  }
// Solidity 0.8.10
/**
 * @dev Retrieve the destination partition from the 'data' field.
 * By convention, a partition change is requested ONLY when 'data' starts
 * with the flag: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
 * When the flag is detected, the destination tranche is extracted from the
 * 32 bytes following the flag.
 * @param fromPartition Partition of the tokens to transfer.
 * @param data Information attached to the transfer. [CAN CONTAIN THE DESTINATION PARTITION]
 * @return toPartition Destination partition.
 */
function _getDestinationPartition(bytes32 fromPartition, bytes memory data) internal pure returns(bytes32 toPartition) {
    bytes32 changePartitionFlag = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
    bytes32 flag;
    assembly {
      flag := mload(add(data, 32))
    }
    if(flag == changePartitionFlag) {
      assembly {
        toPartition := mload(add(data, 64))
      }
    } else {
      toPartition = fromPartition;
    }
  }
// Solidity 0.8.10
/**
 * @dev Remove a token from a specific partition.
 * @param from Token holder.
 * @param partition Name of the partition.
 * @param value Number of tokens to transfer.
 */
function _removeTokenFromPartition(address from, bytes32 partition, uint256 value) internal {
    _balanceOfByPartition[from][partition] = _balanceOfByPartition[from][partition].sub(value);
    _totalSupplyByPartition[partition] = _totalSupplyByPartition[partition].sub(value);

    // If the total supply is zero, finds and deletes the partition.
    if(_totalSupplyByPartition[partition] == 0) {
      uint256 index1 = _indexOfTotalPartitions[partition];
      require(index1 > 0, "50"); // 0x50	transfer failure

      // move the last item into the index being vacated
      bytes32 lastValue = _totalPartitions[_totalPartitions.length - 1];
      _totalPartitions[index1 - 1] = lastValue; // adjust for 1-based indexing
      _indexOfTotalPartitions[lastValue] = index1;

      //_totalPartitions.length -= 1;
      _totalPartitions.pop();
      _indexOfTotalPartitions[partition] = 0;
    }

    // If the balance of the TokenHolder's partition is zero, finds and deletes the partition.
    if(_balanceOfByPartition[from][partition] == 0) {
      uint256 index2 = _indexOfPartitionsOf[from][partition];
      require(index2 > 0, "50"); // 0x50	transfer failure

      // move the last item into the index being vacated
      bytes32 lastValue = _partitionsOf[from][_partitionsOf[from].length - 1];
      _partitionsOf[from][index2 - 1] = lastValue;  // adjust for 1-based indexing
      _indexOfPartitionsOf[from][lastValue] = index2;

      //_partitionsOf[from].length -= 1;
      _partitionsOf[from].pop();
      _indexOfPartitionsOf[from][partition] = 0;
    }
  }
// Solidity 0.8.10
/**
 * @dev Add a token to a specific partition.
 * @param to Token recipient.
 * @param partition Name of the partition.
 * @param value Number of tokens to transfer.
 */
function _addTokenToPartition(address to, bytes32 partition, uint256 value) internal {
    if(value != 0) {
      if (_indexOfPartitionsOf[to][partition] == 0) {
        _partitionsOf[to].push(partition);
        _indexOfPartitionsOf[to][partition] = _partitionsOf[to].length;
      }
      _balanceOfByPartition[to][partition] = _balanceOfByPartition[to][partition].add(value);

      if (_indexOfTotalPartitions[partition] == 0) {
        _totalPartitions.push(partition);
        _indexOfTotalPartitions[partition] = _totalPartitions.length;
      }
      _totalSupplyByPartition[partition] = _totalSupplyByPartition[partition].add(value);
    }
  }
// Solidity 0.8.10
/**
 * @dev Check for 'ERC1400TokensSender' user extension in ERC1820 registry and call it.
 * @param partition Name of the partition (bytes32 to be left empty for transfers where partition is not specified).
 * @param operator Address which triggered the balance decrease (through transfer or redemption).
 * @param from Token holder.
 * @param to Token recipient for a transfer and 0x for a redemption.
 * @param value Number of tokens the token holder balance is decreased by.
 * @param data Extra information.
 * @param operatorData Extra information, attached by the operator (if any).
 */
function _callSenderExtension(
    bytes32 partition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
  )
    internal
  {
    address senderImplementation;
    senderImplementation = interfaceAddr(from, ERC1400_TOKENS_SENDER);
    if (senderImplementation != address(0)) {
      IERC1400TokensSender(senderImplementation).tokensToTransfer(msg.data, partition, operator, from, to, value, data, operatorData);
    }
  }
// Solidity 0.8.10
/**
 * @dev Perform the issuance of tokens.
 * @param operator Address which triggered the issuance.
 * @param to Token recipient.
 * @param value Number of tokens issued.
 * @param data Information attached to the issuance, and intended for the recipient (to).
 */
function _issue(address operator, address to, uint256 value, bytes memory data)
    internal
    isNotMigratedToken  
  {
    require(_isMultiple(value), "50"); // 0x50	transfer failure
    require(to != address(0), "57"); // 0x57	invalid receiver

    _totalSupply = _totalSupply.add(value);
    _balances[to] = _balances[to].add(value);

    emit Issued(operator, to, value, data);
    emit Transfer(address(0), to, value); // ERC20 retrocompatibility
  }
// Solidity 0.8.10
/**
 * @dev Issue tokens from a specific partition.
 * @param toPartition Name of the partition.
 * @param operator The address performing the issuance.
 * @param to Token recipient.
 * @param value Number of tokens to issue.
 * @param data Information attached to the issuance.
 */
function _issueByPartition(
    bytes32 toPartition,
    address operator,
    address to,
    uint256 value,
    bytes memory data
  )
    internal
  {
    _callMintExtension(toPartition, operator, address(0), to, value, data, "");

    _issue(operator, to, value, data);
    _addTokenToPartition(to, toPartition, value);

    _callRecipientExtension(toPartition, operator, address(0), to, value, data, "");

    emit IssuedByPartition(toPartition, operator, to, value, data, "");
  }
// Solidity 0.8.10
/**
 * @dev Perform the token redemption.
 * @param operator The address performing the redemption.
 * @param from Token holder whose tokens will be redeemed.
 * @param value Number of tokens to redeem.
 * @param data Information attached to the redemption.
 */
function _redeem(address operator, address from, uint256 value, bytes memory data)
    internal
    isNotMigratedToken
  {
    require(_isMultiple(value), "50"); // 0x50	transfer failure
    require(from != address(0), "56"); // 0x56	invalid sender
    require(_balances[from] >= value, "52"); // 0x52	insufficient balance

    _balances[from] = _balances[from].sub(value);
    _totalSupply = _totalSupply.sub(value);

    emit Redeemed(operator, from, value, data);
    emit Transfer(from, address(0), value);  // ERC20 retrocompatibility
  }
// Solidity 0.8.10
/**
 * @dev Redeem tokens of a specific partition.
 * @param fromPartition Name of the partition.
 * @param operator The address performing the redemption.
 * @param from Token holder whose tokens will be redeemed.
 * @param value Number of tokens to redeem.
 * @param data Information attached to the redemption.
 * @param operatorData Information attached to the redemption, by the operator (if any).
 */
function _redeemByPartition(
    bytes32 fromPartition,
    address operator,
    address from,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
  )
    internal
  {
    require(_balanceOfByPartition[from][fromPartition] >= value, "52"); // 0x52	insufficient balance

    _callSenderExtension(fromPartition, operator, from, address(0), value, data, operatorData);
    _callRedeemExtension(fromPartition, operator, from, address(0), value, data, operatorData);

    _removeTokenFromPartition(from, fromPartition, value);
    _redeem(operator, from, value, data);

    emit RedeemedByPartition(fromPartition, operator, from, value, operatorData);
  }
// Solidity 0.8.10
/**
 * @dev Redeem tokens from a default partitions.
 * @param operator The address performing the redeem.
 * @param from Token holder.
 * @param value Number of tokens to redeem.
 * @param data Information attached to the redemption.
 */
function _redeemByDefaultPartitions(
    address operator,
    address from,
    uint256 value,
    bytes memory data
  )
    internal
  {
    require(_defaultPartitions.length != 0, "55"); // 0x55	funds locked (lockup period)

    uint256 _remainingValue = value;
    uint256 _localBalance;

    for (uint i = 0; i < _defaultPartitions.length; i++) {
      _localBalance = _balanceOfByPartition[from][_defaultPartitions[i]];
      if(_remainingValue <= _localBalance) {
        _redeemByPartition(_defaultPartitions[i], operator, from, _remainingValue, data, "");
        _remainingValue = 0;
        break;
      } else {
        _redeemByPartition(_defaultPartitions[i], operator, from, _localBalance, data, "");
        _remainingValue = _remainingValue - _localBalance;
      }
    }

    require(_remainingValue == 0, "52"); // 0x52	insufficient balance
  }
// Solidity 0.8.10
/**
 * @dev Know the reason on success or failure based on the EIP-1066 application-specific status codes.
 * @param payload Payload of the initial transaction.
 * @param partition Name of the partition.
 * @param operator The address performing the transfer.
 * @param from Token holder.
 * @param to Token recipient.
 * @param value Number of tokens to transfer.
 * @param data Information attached to the transfer. [CAN CONTAIN THE DESTINATION PARTITION]
 * @param operatorData Information attached to the transfer, by the operator (if any).
 * @return ESC (Ethereum Status Code) following the EIP-1066 standard.
 * @return Additional bytes32 parameter that can be used to define
 * application specific reason codes with additional details (for example the
 * transfer restriction rule responsible for making the transfer operation invalid).
 * @return Destination partition.
 */
function canTransfer(bytes memory payload, bytes32 partition, address operator, address from, address to, uint256 value, bytes memory data, bytes memory operatorData)
    external
    returns (bytes1, bytes32, bytes32)
  {
    if(_balanceOfByPartition[from][partition] < value) {
        return(hex"52", "", partition); // 0x52	insufficient balance
    }
    
    address validatorImplementation = interfaceAddr(address(this), ERC1400_TOKENS_VALIDATOR);
    if (validatorImplementation != address(0)) {
      IERC1400TokensValidator(validatorImplementation).tokensToValidate(msg.data, partition, operator, from, to, value, data, operatorData);
    }
    
    return(hex"00", "", partition);
  }
// Solidity 0.8.10
/**
 * @dev Set list of token controllers.
 * @param operators Controller addresses.
 */
function _setControllers(address[] memory operators) internal {
    for (uint i = 0; i<_controllers.length; i++){
      _isController[_controllers[i]] = false;
    }
    for (uint j = 0; j<operators.length; j++){
      _isController[operators[j]] = true;
    }
    _controllers = operators;
  }
// Solidity 0.8.10
/**
 * @dev Set list of token partition controllers.
 * @param partition Name of the partition.
 * @param operators Controller addresses.
 */
function _setPartitionControllers(bytes32 partition, address[] memory operators) internal {
     for (uint i = 0; i<_controllersByPartition[partition].length; i++){
       _isControllerByPartition[partition][_controllersByPartition[partition][i]] = false;
     }
     for (uint j = 0; j<operators.length; j++){
       _isControllerByPartition[partition][operators[j]] = true;
     }
     _controllersByPartition[partition] = operators;
   }