lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
/// @dev Checks if rounding error > 0.1%.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return Rounding error is present.
function isRoundingError(uint numerator, uint denominator, uint target)
        public
        constant
        returns (bool)
    {
        uint remainder = mulmod(target, numerator, denominator);
        if (remainder == 0) return false; // No rounding error.

        uint errPercentageTimes1000000 = safeDiv(
            safeMul(remainder, 1000000),
            safeMul(numerator, target)
        );
        return errPercentageTimes1000000 > 1000;
    }
// Solidity 0.4.18
/// @dev Get token balance of an address.
/// @param token Address of token.
/// @param owner Address of owner.
/// @return Token balance of owner.
function getBalance(address token, address owner)
        internal
        constant  // The called token contract may attempt to change state, but will not be able to due to an added gas limit.
        returns (uint)
    {
        return Token(token).balanceOf.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner); // Limit gas to prevent reentrancy
    }
// Solidity 0.4.18
/// @dev Get allowance of token given to TokenTransferProxy by an address.
/// @param token Address of token.
/// @param owner Address of owner.
/// @return Allowance of token given to TokenTransferProxy by owner.
function getAllowance(address token, address owner)
        internal
        constant  // The called token contract may attempt to change state, but will not be able to due to an added gas limit.
        returns (uint)
    {
        return Token(token).allowance.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner, TOKEN_TRANSFER_PROXY_CONTRACT); // Limit gas to prevent reentrancy
    }
// Solidity 0.5.8
/**
 * @dev  Decreaese locking time
 * @param _affectiveAddress Address of the locked address
 * @param _decreasedTime Time in days to be affected
 */
function decreaseLockingTimeByAddress(address _affectiveAddress, uint _decreasedTime) external onlyOwner returns(bool){
          require(_decreasedTime > 0 && time[_affectiveAddress] > now, "Please check address status or Incorrect input");
          time[_affectiveAddress] = time[_affectiveAddress] - (_decreasedTime * 1 days);
          return true;
      }
// Solidity 0.5.8
/**
 * @dev Increase locking time
 * @param _affectiveAddress Address of the locked address
 * @param _increasedTime Time in days to be affected
 */
function increaseLockingTimeByAddress(address _affectiveAddress, uint _increasedTime) external onlyOwner returns(bool){
          require(_increasedTime > 0 && time[_affectiveAddress] > now, "Please check address status or Incorrect input");
          time[_affectiveAddress] = time[_affectiveAddress] + (_increasedTime * 1 days);
          return true;
      }
// Solidity 0.6.12
/// @notice Returns the position information associated with a given token ID.
/// @dev Throws if the token ID is not valid.
/// @param tokenId The ID of the token that represents the position
/// @return nonce The nonce for permits
/// @return operator The address that is approved for spending
/// @return token0 The address of the token0 for a specific pool
/// @return token1 The address of the token1 for a specific pool
/// @return fee The fee associated with the pool
/// @return tickLower The lower end of the tick range for the position
/// @return tickUpper The higher end of the tick range for the position
/// @return liquidity The liquidity of the position
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(uint256 tokenId)
        external
        view
        returns (
            uint96 nonce, // [0]
            address operator, // [1]
            address token0, // [2]
            address token1, // [3]
            uint24 fee, // [4]
            int24 tickLower, // [5]
            int24 tickUpper, // [6]
            uint128 liquidity, // [7]
            uint256 feeGrowthInside0LastX128, // [8]
            uint256 feeGrowthInside1LastX128, // [9]
            uint128 tokensOwed0, // [10]
            uint128 tokensOwed1 // [11]
        );
// Solidity 0.6.6
/**
 * @dev add liquidity to LP
 */
function _adLp(uint256 ethAmount, address tokenAddress)
        private
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        )
    {
        uint256 reserveA;
        uint256 reserveB;

        (reserveA, reserveB) = UniswapV2Library.getReserves(
            _uniswapFactory,
            _weth,
            tokenAddress
        );

        uint256 tokenAmount = UniswapV2Library.quote(
            ethAmount,
            reserveA,
            reserveB
        );

        TransferHelper.safeApprove(
            tokenAddress,
            _uniswapRouterAddress,
            tokenAmount
        );

        (amountToken, amountETH, liquidity) = _uniswapRouter02.addLiquidityETH{
            value: ethAmount
        }(
            tokenAddress,
            tokenAmount,
            tokenAmount,
            1,
            address(this),
            block.timestamp + 1 days
        );

        emit onLpvAdded(tokenAmount, amountETH, liquidity, tokenAddress);
    }
// Solidity 0.6.6
/**
 * @dev update the internal list of purchases
 */
function _updateBalance(uint256 ethAmount, uint256 vPUREAmount) private {
        _vCrowdsaleBalance[msg.sender].ethAmount = _vCrowdsaleBalance[msg
            .sender]
            .ethAmount
            .add(ethAmount);
        // safetly check for the total amount of ETH bought by a single user
        // it should not exceed 50 ETH
        require(
            _vCrowdsaleBalance[msg.sender].ethAmount <= _ETHMAX * 10**18,
            "The total amount of ETH exceeded maximul value: 50 ETH"
        );

        _vCrowdsaleBalance[msg.sender].vPUREAmount = _vCrowdsaleBalance[msg
            .sender]
            .vPUREAmount
            .add(vPUREAmount);
    }
// Solidity 0.7.6
/// @inheritdoc IPeripheryPaymentsWithFee
function unwrapWETH9WithFee(
        uint256 amountMinimum,
        address recipient,
        uint256 feeBips,
        address feeRecipient
    ) public payable override {
        require(feeBips > 0 && feeBips <= 100);

        uint256 balanceWETH9 = IWETH9(WETH9).balanceOf(address(this));
        require(balanceWETH9 >= amountMinimum, 'Insufficient WETH9');

        if (balanceWETH9 > 0) {
            IWETH9(WETH9).withdraw(balanceWETH9);
            uint256 feeAmount = balanceWETH9.mul(feeBips) / 10_000;
            if (feeAmount > 0) TransferHelper.safeTransferETH(feeRecipient, feeAmount);
            TransferHelper.safeTransferETH(recipient, balanceWETH9 - feeAmount);
        }
    }
// Solidity 0.8.7
/// @dev presale mint for whitelisted
function presalemint(uint256 tokens, bytes32[] calldata merkleProof) public payable  {
    require(!paused, "SHIBNFT: oops contract is paused");
    require(preSale, "SHIBNFT: Presale Hasn't started yet");
    require(MerkleProof.verify(merkleProof, merkleRoot, keccak256(abi.encodePacked(msg.sender))), "SHIBNFT: You are not Whitelisted");
    uint256 supply = totalSupply();
    uint256 ownerTokenCount = balanceOf(_msgSender());
    require(ownerTokenCount + tokens <= MaxperWalletWl, "SHIBNFT: Max NFT Per Wallet exceeded");
    require(tokens > 0, "SHIBNFT: need to mint at least 1 NFT");
    require(tokens <= MaxperTxWl, "SHIBNFT: max mint per Tx exceeded");
    require(supply + tokens <= WlSupply, "SHIBNFT: Whitelist MaxSupply exceeded");
    require(msg.value >= wlcost * tokens, "SHIBNFT: insufficient funds");

      _safeMint(_msgSender(), tokens);
    
  }
// Solidity 0.8.7
/// @dev use it for giveaway and mint for yourself
function gift(uint256 _mintAmount, address destination) public onlyOwner {
    require(_mintAmount > 0, "need to mint at least 1 NFT");
    uint256 supply = totalSupply();
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

      _safeMint(destination, _mintAmount);
    
  }
// Solidity 0.7.6
/**
 * @notice Migrate all funds from old strategy to new strategy
 * Requirements:
 * - Only owner of this contract call this function
 * - This contract is not locked
 * - Pending strategy is set
 */
function migrateFunds() external onlyOwner {
        require(
            unlockTime <= block.timestamp &&
                unlockTime + 1 days >= block.timestamp,
            "Function locked"
        );
        require(
            token.balanceOf(address(strategy)) > 0,
            "No balance to migrate"
        );
        require(pendingStrategy != address(0), "No pendingStrategy");
        uint256 _amount = token.balanceOf(address(strategy));

        token.safeTransferFrom(address(strategy), pendingStrategy, _amount);
        // Remove balance of old strategy token
        IERC20 oldStrategyToken = IERC20(address(strategy));
        oldStrategyToken.safeTransfer(
            address(strategy),
            oldStrategyToken.balanceOf(address(this))
        );

        // Set new strategy
        address oldStrategy = address(strategy);
        strategy = IStrategy(pendingStrategy);
        pendingStrategy = address(0);
        canSetPendingStrategy = true;

        unlockTime = 0; // Lock back this function
        emit MigrateFunds(oldStrategy, address(strategy), _amount);
    }
// Solidity 0.8.9
/*****************************************************************************
 * Well done, you found it. Now can you solve the puzzle and become a student?
 * If you do pass, how good a student will you be?
 *
 *
 * Notes:
 * * Be careful sharing or copying answers, they need to be personalised
 *     for each student and some may change with time.
 * * If you don't know an answer use
 *     0x0000000000000000000000000000000000000000000000000000000000000000
 ******************************************************************************/
function mint(
        bytes32 _personalisedAnswer1,
        bytes32 _personalisedAnswer2,
        bytes32 _personalisedAnswer3,
        bytes32 _personalisedAnswer4,
        bytes32 _personalisedAnswer5
    ) external payable {
        if (msg.sender.isContract()) {
            revert NoContractCall();
        }
        if (!entrancePuzzleOpen) {
            revert PuzzleNotReady();
        }
        uint supply = _owners.length;
        if (supply >= MAX_SUPPLY) {
            revert SupplyExhausted();
        }
        if (msg.value != entrancePuzzlePrice) {
            revert InvalidAmountSent();
        }
        uint _answer4 = (block.number - schoolBuilt) / 1650;
        string memory _answer5 = Base64.ENCODE("Encode this");

        bool answer1Correct = personaliseString(answer1, msg.sender) == _personalisedAnswer1;
        bool answer2Correct = personaliseNumber(_answer2, msg.sender) == _personalisedAnswer2;
        bool answer3Correct = personaliseNumber(_answer3, msg.sender) == _personalisedAnswer3;
        bool answer4Correct = personaliseNumber(_answer4, msg.sender) == _personalisedAnswer4;
        bool answer5Correct = personaliseString(_answer5, msg.sender) == _personalisedAnswer5;

        if (!(answer1Correct ||
              answer2Correct ||
              answer3Correct ||
              answer4Correct ||
              answer5Correct)) {
            revert YouFailed();
        }
        
        _internalMint(
            supply,
            answer1Correct,
            answer2Correct,
            answer3Correct,
            answer4Correct,
            answer5Correct
        );
    }
// Solidity 0.8.9
// Optional: Give your student a name and it will appear in the image.
//   Free but you'll have to pay gas.
//   Name must be 1-12 alphanumeric characters or space.
function setStudentName(string calldata _studentName, uint256 _tokenId) external {
        if (msg.sender != ownerOf(_tokenId)) revert NotOwnerOfToken();
        bytes memory nameBytes = bytes(_studentName);
        uint256 nameLength = nameBytes.length;
        if (nameLength == 0) revert InvalidName();
        if (nameLength > 12) revert InvalidName();
        for (uint256 i; i < nameLength;) {
            bytes1 char = nameBytes[i];
            if (!(char > 0x2F && char < 0x3A) && // 0-9
                !(char > 0x40 && char < 0x5B) && // A-Z
                !(char > 0x60 && char < 0x7B) && // a-z
                !(char == 0x20)) { // space
                revert InvalidName();
            }
            unchecked { ++i; }
        }
        studentNames[_tokenId] = _studentName;
    }
// Solidity 0.8.9
/*****************************************************************
 ************************ Future puzzles *************************
 * Some puzzles will be free (enter 0 in the amount field)
 *   although you can donate if you are enjoying the school.
 * More complex puzzles and metadata that take us considerable
 *   time to build may have a small fee.
 ****************************************************************/
function attemptPuzzle(
        uint256 _tokenId,
        uint _puzzleIndex,
        bytes32 _personalisedAnswer1,
        bytes32 _personalisedAnswer2,
        bytes32 _personalisedAnswer3,
        bytes32 _personalisedAnswer4,
        bytes32 _personalisedAnswer5
    ) external payable {
        if (msg.sender.isContract()) {
            revert NoContractCall();
        }
        if (_puzzleIndex >= puzzles.length || !puzzles[_puzzleIndex].open) {
            revert PuzzleNotReady();
        }
        if (msg.value < puzzles[_puzzleIndex].puzzlePrice) {
            revert InvalidAmountSent();
        }
        if (msg.sender != ownerOf(_tokenId)) {
            revert NotOwnerOfToken();
        }
        if (_alreadyAttempted(_puzzleIndex, _tokenId)) {
            revert PuzzleAlreadyAttempted();
        }
        address puzzleAddress = puzzles[_puzzleIndex].puzzleAddress;

        uint8 puzzleScore = SchoolOfHardBlocksPuzzle(puzzleAddress).attemptPuzzle(
            msg.sender,
            _personalisedAnswer1,
            _personalisedAnswer2,
            _personalisedAnswer3,
            _personalisedAnswer4,
            _personalisedAnswer5
        );
        scores[_tokenId] += puzzleScore;
        _setAttempted(_puzzleIndex, _tokenId);
    }
// Solidity 0.8.6
/**
 * @notice Determines if the byte encoded description of a position(s) is valid.
 * The description will only make sense in context of the product.
 * @dev This function should be overwritten in inheriting Product contracts.
 * @param positionDescription The description to validate.
 * @return isValid True if is valid.
 */
function isValidPositionDescription(bytes memory positionDescription) public view virtual override returns (bool isValid) {
        // check length
        // solhint-disable-next-line var-name-mixedcase
        uint256 ADDRESS_SIZE = 20;
        // must be concatenation of one or more addresses
        if (positionDescription.length == 0 || positionDescription.length % ADDRESS_SIZE != 0) return false;
        address lqtyStaking = _troveManager.lqtyStaking();
        address stabilityPool = _troveManager.stabilityPool();
        // check all addresses in list
        for(uint256 offset = 0; offset < positionDescription.length; offset += ADDRESS_SIZE) {
            // get next address
            address positionContract;
            // solhint-disable-next-line no-inline-assembly
            assembly {
                positionContract := div(mload(add(add(positionDescription, 0x20), offset)), 0x1000000000000000000000000)
            }
            // must be one of TroveManager, LqtyStaking, or StabilityPool
            if (( address(_troveManager) != positionContract) && (lqtyStaking !=  positionContract) && (stabilityPool != positionContract)) return false;
        }
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Wipes the balance of a frozen address, burning the tokens
 * and setting the approval to zero.
 * @param _addr The new frozen address to wipe.
 */
function wipeFrozenAddress(address _addr) public onlyLawEnforcementRole {
        require(frozen[_addr], "address is not frozen");
        uint256 _balance = balances[_addr];
        balances[_addr] = 0;
        totalSupply_ = totalSupply_.sub(_balance);
        emit FrozenAddressWiped(_addr);
        emit SupplyDecreased(_addr, _balance);
        emit Transfer(_addr, address(0), _balance);
    }
// Solidity 0.4.24
/**
 * @dev Sets a new supply controller address.
 * @param _newSupplyController The address allowed to burn/mint tokens to control supply.
 */
function setSupplyController(address _newSupplyController) public {
        require(msg.sender == supplyController || msg.sender == owner, "only SupplyController or Owner");
        require(_newSupplyController != address(0), "cannot set supply controller to address zero");
        emit SupplyControllerSet(supplyController, _newSupplyController);
        supplyController = _newSupplyController;
    }
// Solidity 0.4.24
/**
 * @dev Decreases the total supply by burning the specified number of tokens from the supply controller account.
 * @param _value The number of tokens to remove.
 * @return A boolean that indicates if the operation was successful.
 */
function decreaseSupply(uint256 _value) public onlySupplyController returns (bool success) {
        require(_value <= balances[supplyController], "not enough supply");
        balances[supplyController] = balances[supplyController].sub(_value);
        totalSupply_ = totalSupply_.sub(_value);
        emit SupplyDecreased(supplyController, _value);
        emit Transfer(supplyController, address(0), _value);
        return true;
    }
// Solidity 0.4.21
/// @return Returns index and ok for the first occurrence starting from
/// index 0
function index(address[] addresses, address a)
        internal pure returns (uint, bool)
    {
        for (uint i = 0; i < addresses.length; i++) {
            if (addresses[i] == a) {
                return (i, true);
            }
        }
        return (0, false);
    }
// Solidity 0.4.21
/// @notice Initializes contract with a list of ERC20 token addresses and
/// corresponding minimum number of units required for a creation unit
/// @param addresses Addresses of the underlying ERC20 token contracts
/// @param quantities Number of token base units required per creation unit
/// @param _creationUnit Number of base units per creation unit
function BsktToken(
        address[] addresses,
        uint256[] quantities,
        uint256 _creationUnit,
        string _name,
        string _symbol
    ) DetailedERC20(_name, _symbol, 18) public {
        require(addresses.length > 0);
        require(addresses.length == quantities.length);
        require(_creationUnit >= 1);

        for (uint256 i = 0; i < addresses.length; i++) {
            tokens.push(TokenInfo({
                addr: addresses[i],
                quantity: quantities[i]
            }));
        }

        creationUnit = _creationUnit;
        name = _name;
        symbol = _symbol;
    }
// Solidity 0.4.21
/// @notice Creates Bskt tokens in exchange for underlying tokens. Before
/// calling, underlying tokens must be approved to be moved by the Bskt
/// contract. The number of approved tokens required depends on baseUnits.
/// @dev If any underlying tokens' `transferFrom` fails (eg. the token is
/// frozen), create will no longer work. At this point a token upgrade will
/// be necessary.
/// @param baseUnits Number of base units to create. Must be a multiple of
/// creationUnit.
function create(uint256 baseUnits)
        external
        whenNotPaused()
        requireNonZero(baseUnits)
        requireMultiple(baseUnits)
    {
        // Check overflow
        require((totalSupply_ + baseUnits) > totalSupply_);

        for (uint256 i = 0; i < tokens.length; i++) {
            TokenInfo memory token = tokens[i];
            ERC20 erc20 = ERC20(token.addr);
            uint256 amount = baseUnits.div(creationUnit).mul(token.quantity);
            require(erc20.transferFrom(msg.sender, address(this), amount));
        }

        mint(msg.sender, baseUnits);
        emit Create(msg.sender, baseUnits);
    }
// Solidity 0.4.21
/// @notice Redeems Bskt tokens in exchange for underlying tokens
/// @param baseUnits Number of base units to redeem. Must be a multiple of
/// creationUnit.
/// @param tokensToSkip Underlying token addresses to skip redemption for.
/// Intended to be used to skip frozen or broken tokens which would prevent
/// all underlying tokens from being withdrawn due to a revert. Skipped
/// tokens are left in the Bskt contract and are unclaimable.
function redeem(uint256 baseUnits, address[] tokensToSkip)
        external
        requireNonZero(baseUnits)
        requireMultiple(baseUnits)
    {
        require(baseUnits <= totalSupply_);
        require(baseUnits <= balances[msg.sender]);
        require(tokensToSkip.length <= tokens.length);
        // Total supply check not required since a user would have to have
        // balance greater than the total supply

        // Burn before to prevent re-entrancy
        burn(msg.sender, baseUnits);

        for (uint256 i = 0; i < tokens.length; i++) {
            TokenInfo memory token = tokens[i];
            ERC20 erc20 = ERC20(token.addr);
            uint256 index;
            bool ok;
            (index, ok) = tokensToSkip.index(token.addr);
            if (ok) {
                continue;
            }
            uint256 amount = baseUnits.div(creationUnit).mul(token.quantity);
            require(erc20.transfer(msg.sender, amount));
        }
        emit Redeem(msg.sender, baseUnits, tokensToSkip);
    }
// Solidity 0.4.21
// @notice Look up token quantity and whether token exists
// @param token Token address to look up
// @return (quantity, ok) Units of underlying token, and whether the
// token was found
function getQuantity(address token) internal view returns (uint256, bool) {
        for (uint256 i = 0; i < tokens.length; i++) {
            if (tokens[i].addr == token) {
                return (tokens[i].quantity, true);
            }
        }
        return (0, false);
    }
// Solidity 0.4.21
/// @notice Owner: Withdraw excess funds which don't belong to Bskt token
/// holders
/// @param token ERC20 token address to withdraw
function withdrawExcessToken(address token)
        external
        onlyOwner
        nonReentrant
    {
        ERC20 erc20 = ERC20(token);
        uint256 withdrawAmount;
        uint256 amountOwned = erc20.balanceOf(address(this));
        uint256 quantity;
        bool ok;
        (quantity, ok) = getQuantity(token);
        if (ok) {
            withdrawAmount = amountOwned.sub(
                totalSupply_.div(creationUnit).mul(quantity)
            );
        } else {
            withdrawAmount = amountOwned;
        }
        require(erc20.transfer(owner, withdrawAmount));
    }
// Solidity 0.6.12
// Purchase one or more card packs for the price in ToshiCoin
function purchasePack(uint256 amount) public {
    require(packPriceInToshiCoin > 0, 'Pack does not exist');
    require(
      toshiCoin.balanceOf(msg.sender) >= packPriceInToshiCoin.mul(amount),
      'Not enough toshiCoin for pack'
    );

    toshiCoin.burn(msg.sender, packPriceInToshiCoin.mul(amount));
    packsPurchased = packsPurchased.add(amount);
    toshimonMinter.mint(msg.sender, minterPackId, amount, '');
  }
// Solidity 0.6.12
// Utility function to check if a value is inside an array
function _isInArray(uint256 _value, uint256[] memory _array)
    internal
    pure
    returns (bool)
  {
    uint256 length = _array.length;
    for (uint256 i = 0; i < length; ++i) {
      if (_array[i] == _value) {
        return true;
      }
    }

    return false;
  }