lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.10
/// @notice Used to compute blockOmega() function, { blockOmega } represents
///         the block when it won't ever be possible to mint another Dollars Nakamoto NFT.
///         It is possible to be computed because of the deterministic state of the current protocol
///         The following algorithm simulate the 10 epochs of the protocol block computation to result blockOmega
function computeBlockOmega()
    private {
        uint256 i = 0;
        uint256 _blockMeta = 0;
        uint256 _epochLen = epochLen;

        while (i < epochMax) {
            if (i > 0) _epochLen *= inflateRatio;
            if (i == 9) {
                blockOmega = blockGenesis + _blockMeta;
                emit Omega(blockOmega);
                break;
            }
            _blockMeta += _epochLen;
            i++;
        }
    }
// Solidity 0.8.10
/// @notice Used to regulate the epoch incrementation and block computation, known as Metas
/// @dev When epoch=0, the { blockOmega } will be computed
///      When epoch!=0 the block length { epochLen } will be multiplied
///      by { inflateRatio } thus making the block length required for each
///      epoch longer according
///
///      { blockMeta } += { epochLen } result the exact block of the next Meta
///      Allow generation mint after incrementing the epoch
function epochRegulator()
    private {
        if (epoch == 0) computeBlockOmega();
        if (epoch > 0) epochLen *= inflateRatio;
        
        blockMeta += epochLen;
        emit Meta(epoch, blockMeta);

        epoch++;

        if (block.number >= blockMeta && epoch < epochMax) {
            epochRegulator();
        }
        
        generationMintAllowed = true;
    }
// Solidity 0.8.10
/// @notice Used to add/remove address from { _allowList }
function setBatchGenesisAllowance(address[] memory batch)
    public onlyOwner {
        uint len = batch.length;
        require(len > 0, "error len");
        
        uint i = 0;
        while (i < len) {
            _allowList[batch[i]] = _allowList[batch[i]] ?
            false : true;
            i++;
        }
    }
// Solidity 0.8.10
/// @notice Used to fetch all { tokenIds } from { owner }
function exposeHeldIds(address owner)
    public view returns(uint[] memory) {
        uint tokenCount = balanceOf(owner);
        uint[] memory tokenIds = new uint[](tokenCount);

        uint i = 0;
        while (i < tokenCount) { 
            tokenIds[i] = tokenOfOwnerByIndex(owner, i);
            i++;
        }
        return tokenIds;
    }
// Solidity 0.8.6
/**
 * @dev Deposit a quantity of bAsset into the platform. Credited aTokens
 *      remain here in the vault. Can only be called by whitelisted addresses
 *      (mAsset and corresponding BasketManager)
 * @param _bAsset              Address for the bAsset
 * @param _amount              Units of bAsset to deposit
 * @param _hasTxFee            Is the bAsset known to have a tx fee?
 * @return quantityDeposited   Quantity of bAsset that entered the platform
 */
function deposit(
        address _bAsset,
        uint256 _amount,
        bool _hasTxFee
    ) external override onlyLP nonReentrant returns (uint256 quantityDeposited) {
        require(_amount > 0, "Must deposit something");

        IAaveATokenV2 aToken = _getATokenFor(_bAsset);

        quantityDeposited = _amount;

        if (_hasTxFee) {
            // If we charge a fee, account for it
            uint256 prevBal = _checkBalance(aToken);
            _getLendingPool().deposit(_bAsset, _amount, address(this), 36);
            uint256 newBal = _checkBalance(aToken);
            quantityDeposited = _min(quantityDeposited, newBal - prevBal);
        } else {
            _getLendingPool().deposit(_bAsset, _amount, address(this), 36);
        }

        emit Deposit(_bAsset, address(aToken), quantityDeposited);
    }
// Solidity 0.8.6
/** @dev Withdraws _totalAmount from the lending pool, sending _amount to user */
function _withdraw(
        address _receiver,
        address _bAsset,
        uint256 _amount,
        uint256 _totalAmount,
        bool _hasTxFee
    ) internal {
        require(_totalAmount > 0, "Must withdraw something");

        IAaveATokenV2 aToken = _getATokenFor(_bAsset);

        if (_hasTxFee) {
            require(_amount == _totalAmount, "Cache inactive for assets with fee");
            _getLendingPool().withdraw(_bAsset, _amount, _receiver);
        } else {
            _getLendingPool().withdraw(_bAsset, _totalAmount, address(this));
            // Send redeemed bAsset to the receiver
            IERC20(_bAsset).safeTransfer(_receiver, _amount);
        }

        emit PlatformWithdrawal(_bAsset, address(aToken), _totalAmount, _amount);
    }
// Solidity 0.8.6
/**
 * @dev Withdraw a quantity of bAsset from the cache.
 * @param _receiver     Address to which the bAsset should be sent
 * @param _bAsset       Address of the bAsset
 * @param _amount       Units of bAsset to withdraw
 */
function withdrawRaw(
        address _receiver,
        address _bAsset,
        uint256 _amount
    ) external override onlyLP nonReentrant {
        require(_amount > 0, "Must withdraw something");
        require(_receiver != address(0), "Must specify recipient");

        IERC20(_bAsset).safeTransfer(_receiver, _amount);

        emit Withdrawal(_bAsset, address(0), _amount);
    }
// Solidity 0.5.11
/*
 * @param _withdrawalAddress address to which funds from this contract will be sent
 */
function setWithdrawalAddress(address payable _withdrawalAddress) public onlyAdmin returns (bool success) {

        require(
            !withdrawalAddressFixed,
            "Withdrawal address already fixed"
        );

        require(
            _withdrawalAddress != address(0),
            "Wrong address: 0x0"
        );

        require(
            _withdrawalAddress != address(this),
            "Wrong address: contract itself"
        );

        emit WithdrawalAddressChanged(withdrawalAddress, _withdrawalAddress, msg.sender);

        withdrawalAddress = _withdrawalAddress;

        return true;
    }
// Solidity 0.5.11
/**
 * @param _withdrawalAddress Address to which funds from this contract will be sent.
 *
 * @dev This function can be called one time only.
 */
function fixWithdrawalAddress(address _withdrawalAddress) external onlyAdmin returns (bool success) {

        // prevents event if already fixed
        require(
            !withdrawalAddressFixed,
            "Can't change, address fixed"
        );

        // check, to prevent fixing wrong address
        require(
            withdrawalAddress == _withdrawalAddress,
            "Wrong address in argument"
        );

        withdrawalAddressFixed = true;

        emit WithdrawalAddressFixed(withdrawalAddress, msg.sender);

        return true;
    }
// Solidity 0.5.11
/**
 * @dev This function can be called by any user or contract.
 * Possible warning:
 check for reentrancy vulnerability http://solidity.readthedocs.io/en/develop/security-considerations.html#re-entrancy
 * Since we are making a withdrawal to our own contract/address only there is no possible attack using reentrancy vulnerability
 */
function withdrawAllToWithdrawalAddress() external returns (bool success) {

        // http://solidity.readthedocs.io/en/develop/security-considerations.html#sending-and-receiving-ether
        // about <address>.send(uint256 amount) and <address>.transfer(uint256 amount)
        // see: http://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=transfer#address-related
        // https://ethereum.stackexchange.com/questions/19341/address-send-vs-address-transfer-best-practice-usage

        uint sum = address(this).balance;

        if (!withdrawalAddress.send(sum)) {// makes withdrawal and returns true (success) or false

            emit Withdrawal(withdrawalAddress, sum, msg.sender, false);

            return false;
        }

        emit Withdrawal(withdrawalAddress, sum, msg.sender, true);

        return true;
    }
// Solidity 0.5.11
/*
 * @dev This function creates new shares contracts.
 * @param _description Description of the project or organization (can be short text or link to web page)
 * @param _name Name of the token, as required by ERC20.
 * @param _symbol Symbol for the token, as required by ERC20.
 * @param _totalSupply Total supply, as required by ERC20.
 * @param _dividendsPeriodInSeconds Period between dividends payout rounds, in seconds.
 */
function createCryptoSharesContract(
        string calldata _description,
        string calldata _name,
        string calldata _symbol,
        uint _totalSupply,
        uint _dividendsPeriodInSeconds
    ) external payable returns (bool success){

        require(
            msg.value >= price,
            "msg.value is less than price"
        );

        CryptoShares cryptoSharesContract = new CryptoShares();

        cryptoSharesContractsCounter++;

        cryptoSharesContract.initToken(
            cryptoSharesContractsCounter,
            _description,
            _name,
            _symbol,
            _dividendsPeriodInSeconds,
            xEurContractAddress,
            address(cryptonomicaVerification),
            disputeResolutionAgreement
        );

        cryptoSharesContract.issueTokens(
            _totalSupply,
            msg.sender
        );

        cryptoSharesContractsCounter;
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].contractId = cryptoSharesContractsCounter;
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].contractAddress = address(cryptoSharesContract);
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].deployedOnUnixTime = now;
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].name = cryptoSharesContract.name();
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].symbol = cryptoSharesContract.symbol();
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].totalSupply = cryptoSharesContract.totalSupply();
        cryptoSharesContractsLedger[cryptoSharesContractsCounter].dividendsPeriod = cryptoSharesContract.dividendsPeriod();

        emit NewCryptoSharesContractCreated(
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].contractId,
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].contractAddress,
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].name,
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].symbol,
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].totalSupply,
            cryptoSharesContractsLedger[cryptoSharesContractsCounter].dividendsPeriod
        );

        return true;

    }
// Solidity 0.8.4
// Only positions with locked veFXS can accrue yield. Otherwise, expired-locked veFXS
// is de-facto rewards for FXS.
function eligibleCurrentVeFXS(address account) public view returns (uint256) {
        uint256 curr_vefxs_bal = veFXS.balanceOf(account);
        IveFXS.LockedBalance memory curr_locked_bal_pack = veFXS.locked(account);
        
        // Only unexpired veFXS should be eligible
        if (int256(curr_locked_bal_pack.amount) == int256(curr_vefxs_bal)) {
            return 0;
        }
        else {
            return curr_vefxs_bal;
        }
    }
// Solidity 0.8.7
//public payable
function presale( uint quantity ) external payable {
    require( isPresaleActive,               "Presale is not active"     );
    require( quantity <= MAX_ORDER,         "Order too big"             );
    require( msg.value >= PRESALE_PRICE * quantity, "Ether sent is not correct" );
    require( accessList[msg.sender] > 0,    "Not authorized"            );

    uint supply = totalSupply();
    require( supply + quantity <= MAX_SUPPLY, "Mint/order exceeds supply" );
    accessList[msg.sender] -= quantity;

    for(uint i; i < quantity; ++i){
      _mint( msg.sender, supply++ );
    }
  }
// Solidity 0.8.7
//delegated payable
function burnFrom( address owner, uint[] calldata tokenIds ) external payable onlyDelegates{
    for(uint i; i < tokenIds.length; ++i ){
      require( _exists( tokenIds[i] ), "Burn for nonexistent token" );
      require( _owners[ tokenIds[i] ] == owner, "Owner mismatch" );
      _burn( tokenIds[i] );
    }
  }
// Solidity 0.8.7
//delegated nonpayable
function resurrect( uint[] calldata tokenIds, address[] calldata recipients ) external onlyDelegates{
    require(tokenIds.length == recipients.length,   "Must provide equal tokenIds and recipients" );

    address to;
    uint tokenId;
    address zero = address(0);
    for(uint i; i < tokenIds.length; ++i ){
      to = recipients[i];
      require(recipients[i] != address(0), "resurrect to the zero address" );

      tokenId = tokenIds[i];
      require( !_exists( tokenId ), "can't resurrect existing token" );

      
      _owners[tokenId] = to;
      // Clear approvals
      _approve(zero, tokenId);
      emit Transfer(zero, to, tokenId);
    }
  }
// Solidity 0.8.4
// If the period expired, renew it
function retroCatchUp() internal {
        // Failsafe check
        require(block.timestamp > periodFinish, "Period has not expired yet!");

        // Ensure the provided yield amount is not more than the balance in the contract.
        // This keeps the yield rate in the right range, preventing overflows due to
        // very high values of yieldRate in the earned and yieldPerToken functions;
        // Yield + leftover must be less than 2^256 / 10^18 to avoid overflow.
        uint256 num_periods_elapsed = uint256(block.timestamp.sub(periodFinish)) / yieldDuration; // Floor division to the nearest period
        uint256 balance0 = emittedToken.balanceOf(address(this));
        require(
            yieldRate.mul(yieldDuration).mul(num_periods_elapsed + 1) <=
                balance0,
            "Not enough emittedToken available for yield distribution!"
        );

        periodFinish = periodFinish.add(
            (num_periods_elapsed.add(1)).mul(yieldDuration)
        );

        uint256 yield0 = yieldPerVeFXS();
        yieldPerVeFXSStored = yield0;
        lastUpdateTime = lastTimeYieldApplicable();

        emit YieldPeriodRenewed(emitted_token_address, yieldRate);
    }
// Solidity 0.4.23
/**
 * @dev Burns a specific amount of tokens from another address.
 * @param _value The amount of tokens to be burned.
 * @param _from The address which you want to burn tokens from.
 */
function burnFrom(address _from, uint _value) public returns (bool success) {
        require((balances[_from] > _value) && (_value <= allowed[_from][msg.sender]));
        var _allowance = allowed[_from][msg.sender];
        balances[_from] = balances[_from].sub(_value);
        totalSupply = totalSupply.sub(_value);
        allowed[_from][msg.sender] = _allowance.sub(_value);
        Burn(_from, _value);
        return true;
    }
// Solidity 0.5.4
/**
 * @dev Returns ceil(a / b).
 */
function ceil(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a / b;
        if(a % b == 0) {
            return c;
        }
        else {
            return c + 1;
        }
    }
// Solidity 0.5.4
// *************** Signature ********************** //
function getSignHash(bytes memory _data, uint256 _nonce) internal view returns(bytes32) {
        // use EIP 191
        // 0x1900 + this logic address + data + nonce of signing key
        bytes32 msgHash = keccak256(abi.encodePacked(byte(0x19), byte(0), address(this), _data, _nonce));
        bytes32 prefixedHash = keccak256(abi.encodePacked(SIGN_HASH_PREFIX, msgHash));
        return prefixedHash;
    }
// Solidity 0.5.4
/* get signer address from data
 * @dev Gets an address encoded as the first argument in transaction data
 * @param b The byte array that should have an address as first argument
 * @returns a The address retrieved from the array
 */
function getSignerAddress(bytes memory _b) internal pure returns (address _a) {
        require(_b.length >= 36, "invalid bytes");
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            let mask := 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
            _a := and(mask, mload(add(_b, 36)))
            // b = {length:32}{method sig:4}{address:32}{...}
            // 36 is the offset of the first parameter of the data, if encoded properly.
            // 32 bytes for the length of the bytes array, and the first 4 bytes for the function signature.
            // 32 bytes is the length of the bytes array!!!!
        }
    }
// Solidity 0.5.4
// get method id, first 4 bytes of data
function getMethodId(bytes memory _b) internal pure returns (bytes4 _a) {
        require(_b.length >= 4, "invalid data");
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            // 32 bytes is the length of the bytes array
            _a := mload(add(_b, 32))
        }
    }
// Solidity 0.5.4
/**
 * @dev This method makes it possible for the wallet to comply to interfaces expecting the wallet to
 * implement specific static methods. It delegates the static call to a target contract if the data corresponds
 * to an enabled method, or logs the call otherwise.
 */
function() external payable {
        if(msg.data.length > 0) {
            address logic = enabled[msg.sig];
            if(logic == address(0)) {
                emit Received(msg.value, msg.sender, msg.data);
            }
            else {
                require(LogicManager(manager).isAuthorized(logic), "must be an authorized logic for static call");
                // solium-disable-next-line security/no-inline-assembly
                assembly {
                    calldatacopy(0, 0, calldatasize())
                    let result := staticcall(gas, logic, 0, calldatasize(), 0, 0)
                    returndatacopy(0, 0, returndatasize())
                    switch result
                    case 0 {revert(0, returndatasize())}
                    default {return (0, returndatasize())}
                }
            }
        }
    }
// Solidity 0.8.4
/**
 * @notice Approves this contract to transfer `amount` tokens from the `msg.sender`
 * and stakes these tokens. Only the owner of tokens (i.e. the staker) may call.
 * @dev This contract does not need to be approve()'d in advance - see EIP-2612
 * @param owner - The owner of tokens being staked (i.e. the `msg.sender`)
 * @param amount - Amount to stake
 * @param v - "v" param of the signature from `owner` for "permit"
 * @param r - "r" param of the signature from `owner` for "permit"
 * @param s - "s" param of the signature from `owner` for "permit"
 * @param stakeType - Type of the stake
 * @param data - Arbitrary data for "RewardMaster" (zero, if inapplicable)
 * @return stake ID
 */
function permitAndStake(
        address owner,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s,
        bytes4 stakeType,
        bytes calldata data
    ) external returns (uint256) {
        require(owner == msg.sender, "Staking: owner must be msg.sender");
        TOKEN.permit(owner, address(this), amount, deadline, v, r, s);
        return _createStake(owner, amount, stakeType, data);
    }
// Solidity 0.8.4
/**
 * @notice Claims staked token
 * @param stakeID - ID of the stake to claim
 * @param data - Arbitrary data for "RewardMaster" (zero, if inapplicable)
 * @param _isForced - Do not revert if "RewardMaster" fails
 */
function unstake(
        uint256 stakeID,
        bytes calldata data,
        bool _isForced
    ) external stakeExist(msg.sender, stakeID) {
        Stake memory _stake = stakes[msg.sender][stakeID];

        require(_stake.claimedAt == 0, "Staking: Stake claimed");
        require(_stake.lockedTill < safe32TimeNow(), "Staking: Stake locked");

        if (_stake.delegatee != address(0)) {
            _undelegatePower(_stake.delegatee, msg.sender, _stake.amount);
        }
        _removePower(msg.sender, _stake.amount);

        stakes[msg.sender][stakeID].claimedAt = safe32TimeNow();

        totalStaked = safe96(uint256(totalStaked) - uint256(_stake.amount));

        emit StakeClaimed(msg.sender, stakeID);

        // known contract - reentrancy guard and `safeTransfer` unneeded
        require(
            TOKEN.transfer(msg.sender, _stake.amount),
            "Staking: transfer failed"
        );

        Terms memory _terms = terms[_stake.stakeType];
        if (_terms.isRewarded) {
            _sendUnstakedMsg(msg.sender, _stake, data, _isForced);
        }
    }
// Solidity 0.8.4
/**
 * @notice Updates vote delegation
 * @param stakeID - ID of the stake to delegate votes uber
 * @param to - address to delegate to
 */
function delegate(uint256 stakeID, address to)
        public
        stakeExist(msg.sender, stakeID)
    {
        require(
            to != GLOBAL_ACCOUNT,
            "Staking: Can't delegate to GLOBAL_ACCOUNT"
        );

        Stake memory s = stakes[msg.sender][stakeID];
        require(s.claimedAt == 0, "Staking: Stake claimed");
        require(s.delegatee != to, "Staking: Already delegated");

        if (s.delegatee == address(0)) {
            _delegatePower(msg.sender, to, s.amount);
        } else {
            if (to == msg.sender) {
                _undelegatePower(s.delegatee, msg.sender, s.amount);
            } else {
                _reDelegatePower(s.delegatee, to, s.amount);
            }
        }

        emit Delegation(msg.sender, s.delegatee, to, stakeID, s.amount);

        stakes[msg.sender][stakeID].delegatee = to;
    }
// Solidity 0.8.4
/// Only for the owner functions
/// @notice Adds a new stake type with given terms
/// @dev May be only called by the {OWNER}
function addTerms(bytes4 stakeType, Terms memory _terms)
        external
        onlyOwner
        nonZeroStakeType(stakeType)
    {
        Terms memory existingTerms = terms[stakeType];
        require(!_isDefinedTerms(existingTerms), "Staking:E1");
        require(_terms.isEnabled, "Staking:E2");

        uint256 _now = timeNow();

        if (_terms.allowedTill != 0) {
            require(_terms.allowedTill > _now, "Staking:E3");
            require(_terms.allowedTill > _terms.allowedSince, "Staking:E4");
        }

        if (_terms.maxAmountScaled != 0) {
            require(
                _terms.maxAmountScaled > _terms.minAmountScaled,
                "Staking:E5"
            );
        }

        // only one of three "lock time" parameters must be non-zero
        if (_terms.lockedTill != 0) {
            require(
                _terms.exactLockPeriod == 0 && _terms.minLockPeriod == 0,
                "Staking:E6"
            );
            require(
                _terms.lockedTill > _now &&
                    _terms.lockedTill >= _terms.allowedTill,
                "Staking:E7"
            );
        } else {
            require(
                // one of two params must be non-zero
                (_terms.exactLockPeriod == 0) != (_terms.minLockPeriod == 0),
                "Staking:E8"
            );
        }

        terms[stakeType] = _terms;
        emit TermsAdded(stakeType);
    }
// Solidity 0.7.4
/// This function is from Nick Johnson's string utils library
function memcpy(uint dest, uint src, uint len) private pure {
        // Copy word-length chunks while possible
        for(; len >= 32; len -= 32) {
            assembly {
                mstore(dest, mload(src))
            }
            dest += 32;
            src += 32;
        }

        // Copy remaining bytes
        uint mask = 256 ** (32 - len) - 1;
        assembly {
            let srcpart := and(mload(src), not(mask))
            let destpart := and(mload(dest), mask)
            mstore(dest, or(destpart, srcpart))
        }
    }