lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.15
/// calculates the total discount of all buckets with a timestamp > block.timestamp
function calcTotalDiscount() public view returns(uint) {
        uint normalizedBlockTimestamp = uniqueDayTimestamp(block.timestamp);
        uint sum = 0;

        uint currDate = normalizedBlockTimestamp;

        if (currDate > lastBucket) {
            return 0;
        }

        // only buckets after the block.timestamp are relevant for the discount
        // assuming its more gas efficient to iterate over time to find the first one instead of iterating the list from the beginning
        // not true if buckets are only sparsely populated over long periods of time
        while(buckets[currDate].next == 0) { currDate = currDate + 1 days; }

        while(currDate != NullDate)
        {
            sum = safeAdd(sum, calcDiscount(buckets[currDate].value, normalizedBlockTimestamp, currDate));
            currDate = buckets[currDate].next;
        }
        return sum;
    }
// Solidity 0.5.15
/// returns the NAV (net asset value) of the pool
function currentNAV() public view returns(uint) {
        // calculates the NAV for ongoing loans with a maturityDate date in the future
        uint nav_ = calcTotalDiscount();
        // include ovedue assets to the current NAV calculation
        for (uint i = 0; i < writeOffs.length; i++) {
            // multiply writeOffGroupDebt with the writeOff rate
            nav_ = safeAdd(nav_, rmul(pile.rateDebt(writeOffs[i].rateGroup), writeOffs[i].percentage.value));
        }
        return nav_;
    }
// Solidity 0.4.26
//Claim tokens for first/second reserve wallets
function claimTokenReserve() onlyTokenReserve locked public {

        address reserveWallet = msg.sender;

        // Can't claim before Lock ends

        require(block.timestamp > timeLocks[reserveWallet]); 

        // Must Only claim once

        require(claimed[reserveWallet] == 0);  

        uint256 amount = allocations[reserveWallet];

        claimed[reserveWallet] = amount;  // 一次性解锁发放

        require(token.transfer(reserveWallet, amount));

        Distributed(reserveWallet, amount);

    }
// Solidity 0.4.26
//Claim tokens for Libra team reserve wallet
function claimTeamReserve() onlyTeamReserve locked public {

        uint256 vestingStage = teamVestingStage(); 

        //Amount of tokens the team should have at this vesting stage

        uint256 totalUnlocked = vestingStage.mul(allocations[teamReserveWallet]).div(teamVestingStages); // 总的解锁量

        require(totalUnlocked <= allocations[teamReserveWallet]);

        //Previously claimed tokens must be less than what is unlocked

        require(claimed[teamReserveWallet] < totalUnlocked); 

        uint256 payment = totalUnlocked.sub(claimed[teamReserveWallet]); 

        claimed[teamReserveWallet] = totalUnlocked;

        require(token.transfer(teamReserveWallet, payment)); 

        Distributed(teamReserveWallet, payment);

    }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// 1,000 REKT Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
        require(now >= startDate && now <= endDate);
        uint tokens;
        if (now <= bonusEnds) {
            tokens = msg.value * 1200;
        } else {
            tokens = msg.value * 1000;
        }
        balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
        _totalSupply = safeAdd(_totalSupply, tokens);
        Transfer(address(0), msg.sender, tokens);
        owner.transfer(msg.value);
    }
// Solidity 0.7.0
/**
 * Mints Fuego NFTs
 */
function mintFuego(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint Flames");
        require(numberOfTokens <= maxFuegoPurchase, "Can only mint 20 tokens at a time");
        require(totalSupply().add(numberOfTokens) <= MAX_FUEGO, "Purchase would exceed max supply of Flames");
        require(FuegoPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply();
            if (totalSupply() < MAX_FUEGO) {
                _safeMint(msg.sender, mintIndex);
            }
        }

        // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
        // the end of pre-sale, set the starting index block
        if (startingIndexBlock == 0 && (totalSupply() == MAX_FUEGO || block.timestamp >= REVEAL_TIMESTAMP)) {
            startingIndexBlock = block.number;
        } 
    }
// Solidity 0.8.10
/**
 * @notice Creates a proposal to replace, remove or add an adapter.
 * @dev If the adapterAddress is equal to 0x0, the adapterId is removed from the registry if available.
 * @dev If the adapterAddress is a reserved address, it reverts.
 * @dev keys and value must have the same length.
 * @dev proposalId can not be reused.
 * @param dao The dao address.
 * @param proposalId Tproposal details
 * @param proposal The proposal details
 * @param data Additional data to pass to the voting contract and identify the submitter
 */
function submitProposal(
        DaoRegistry dao,
        bytes32 proposalId,
        ProposalDetails calldata proposal,
        Configuration[] memory configs,
        bytes calldata data
    ) external override onlyMember(dao) reentrancyGuard(dao) {
        require(
            proposal.keys.length == proposal.values.length,
            "must be an equal number of config keys and values"
        );

        require(
            proposal.extensionAddresses.length ==
                proposal.extensionAclFlags.length,
            "must be an equal number of extension addresses and acl"
        );

        require(
            isNotReservedAddress(proposal.adapterOrExtensionAddr),
            "address is reserved"
        );

        dao.submitProposal(proposalId);

        proposals[address(dao)][proposalId] = proposal;

        Configuration[] storage newConfigs = configurations[address(dao)][
            proposalId
        ];
        for (uint256 i = 0; i < configs.length; i++) {
            Configuration memory config = configs[i];
            newConfigs.push(
                Configuration({
                    key: config.key,
                    configType: config.configType,
                    numericValue: config.numericValue,
                    addressValue: config.addressValue
                })
            );
        }

        IVoting votingContract = IVoting(dao.getAdapterAddress(VOTING));

        address senderAddress = votingContract.getSenderAddress(
            dao,
            address(this),
            data,
            msg.sender
        );

        dao.sponsorProposal(proposalId, senderAddress, address(votingContract));
        votingContract.startNewVotingForProposal(dao, proposalId, data);
    }
// Solidity 0.8.10
/**
 * @notice Processes a proposal that was sponsored.
 * @dev Only members can process a proposal.
 * @dev Only if the voting pass the proposal is processed.
 * @dev Reverts when the adapter address is already in use and it is an adapter addition.
 * @dev Reverts when the extension address is already in use and it is an extension addition.
 * @param dao The dao address.
 * @param proposalId The proposal id.
 */
function processProposal(DaoRegistry dao, bytes32 proposalId)
        external
        override
        reentrancyGuard(dao)
    {
        ProposalDetails memory proposal = proposals[address(dao)][proposalId];

        IVoting votingContract = IVoting(dao.votingAdapter(proposalId));
        require(address(votingContract) != address(0), "adapter not found");

        require(
            votingContract.voteResult(dao, proposalId) ==
                IVoting.VotingState.PASS,
            "proposal did not pass"
        );

        dao.processProposal(proposalId);
        if (proposal.updateType == UpdateType.ADAPTER) {
            dao.replaceAdapter(
                proposal.adapterOrExtensionId,
                proposal.adapterOrExtensionAddr,
                proposal.flags,
                proposal.keys,
                proposal.values
            );
        } else if (proposal.updateType == UpdateType.EXTENSION) {
            _replaceExtension(dao, proposal);
        } else {
            revert("unknown update type");
        }
        _grantExtensionAccess(dao, proposal);
        _saveDaoConfigurations(dao, proposalId);
    }
// Solidity 0.8.10
/**
 * @notice If the extension is already registered, it removes the extension from the DAO Registry.
 * @notice If the adapterOrExtensionAddr is provided, the new address is added as a new extension to the DAO Registry.
 */
function _replaceExtension(DaoRegistry dao, ProposalDetails memory proposal)
        internal
    {
        if (dao.extensions(proposal.adapterOrExtensionId) != address(0x0)) {
            dao.removeExtension(proposal.adapterOrExtensionId);
        }

        if (proposal.adapterOrExtensionAddr != address(0x0)) {
            dao.addExtension(
                proposal.adapterOrExtensionId,
                IExtension(proposal.adapterOrExtensionAddr),
                // The creator of the extension must be set as the DAO owner,
                // which is stored at index 0 in the members storage.
                dao.getMemberAddress(0)
            );
        }
    }
// Solidity 0.8.10
/**
 * @notice Saves to the DAO Registry the ACL Flag that grants the access to the given `extensionAddresses`
 */
function _grantExtensionAccess(
        DaoRegistry dao,
        ProposalDetails memory proposal
    ) internal {
        for (uint256 i = 0; i < proposal.extensionAclFlags.length; i++) {
            dao.setAclToExtensionForAdapter(
                // It needs to be registered as extension
                proposal.extensionAddresses[i],
                // It needs to be registered as adapter
                proposal.adapterOrExtensionAddr,
                // Indicate which access level will be granted
                proposal.extensionAclFlags[i]
            );
        }
    }
// Solidity 0.8.10
/**
 * @notice Saves the numeric/address configurations to the DAO registry
 */
function _saveDaoConfigurations(DaoRegistry dao, bytes32 proposalId)
        internal
    {
        Configuration[] memory configs = configurations[address(dao)][
            proposalId
        ];

        for (uint256 i = 0; i < configs.length; i++) {
            Configuration memory config = configs[i];
            if (ConfigType.NUMERIC == config.configType) {
                dao.setConfiguration(config.key, config.numericValue);
            } else if (ConfigType.ADDRESS == config.configType) {
                dao.setAddressConfiguration(config.key, config.addressValue);
            }
        }
    }
// Solidity 0.5.0
/// @return the negation of p, i.e. p.add(p.negate()) should be zero.
function negate(G1Point memory p) internal pure returns (G1Point memory) {
        // The prime q in the base field F_q for G1
        uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
        if (p.X == 0 && p.Y == 0)
            return G1Point(0, 0);
        return G1Point(p.X, q - (p.Y % q));
    }
// Solidity 0.5.0
/// @return the sum of two points of G1
function pointAdd(G1Point memory p1, G1Point memory p2)
        internal view returns (G1Point memory r)
    {
        uint[4] memory input;
        input[0] = p1.X;
        input[1] = p1.Y;
        input[2] = p2.X;
        input[3] = p2.Y;
        bool success;
        assembly {
            success := staticcall(sub(gas, 2000), 6, input, 0xc0, r, 0x60)
        }
        require(success);
    }
// Solidity 0.5.0
/// @return the product of a point on G1 and a scalar, i.e.
/// p == p.mul(1) and p.add(p) == p.mul(2) for all points p.
function pointMul(G1Point memory p, uint s)
        internal view returns (G1Point memory r)
    {
        uint[3] memory input;
        input[0] = p.X;
        input[1] = p.Y;
        input[2] = s;
        bool success;
        assembly {
            success := staticcall(sub(gas, 2000), 7, input, 0x80, r, 0x60)
        }
        require (success);
    }
// Solidity 0.5.0
/// @return the result of computing the pairing check
/// e(p1[0], p2[0]) *  .... * e(p1[n], p2[n]) == 1
/// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
/// return true.
function pairing(G1Point[] memory p1, G2Point[] memory p2)
        internal view returns (bool)
    {
        require(p1.length == p2.length);
        uint elements = p1.length;
        uint inputSize = elements * 6;
        uint[] memory input = new uint[](inputSize);
        for (uint i = 0; i < elements; i++)
        {
            input[i * 6 + 0] = p1[i].X;
            input[i * 6 + 1] = p1[i].Y;
            input[i * 6 + 2] = p2[i].X[0];
            input[i * 6 + 3] = p2[i].X[1];
            input[i * 6 + 4] = p2[i].Y[0];
            input[i * 6 + 5] = p2[i].Y[1];
        }
        uint[1] memory out;
        bool success;
        assembly {
            success := staticcall(sub(gas, 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
        }
        require(success);
        return out[0] != 0;
    }
// Solidity 0.5.0
/// Convenience method for a pairing check for two pairs.
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2)
        internal view returns (bool)
    {
        G1Point[] memory p1 = new G1Point[](2);
        G2Point[] memory p2 = new G2Point[](2);
        p1[0] = a1;
        p1[1] = b1;
        p2[0] = a2;
        p2[1] = b2;
        return pairing(p1, p2);
    }
// Solidity 0.5.0
/// Convenience method for a pairing check for four pairs.
function pairingProd4(
            G1Point memory a1, G2Point memory a2,
            G1Point memory b1, G2Point memory b2,
            G1Point memory c1, G2Point memory c2,
            G1Point memory d1, G2Point memory d2
    )
        internal view returns (bool)
    {
        G1Point[] memory p1 = new G1Point[](4);
        G2Point[] memory p2 = new G2Point[](4);
        p1[0] = a1;
        p1[1] = b1;
        p1[2] = c1;
        p1[3] = d1;
        p2[0] = a2;
        p2[1] = b2;
        p2[2] = c2;
        p2[3] = d2;
        return pairing(p1, p2);
    }
// Solidity 0.5.0
/**
 * MiMC-p/p with exponent of 7
 * 
 * Recommended at least 46 rounds, for a polynomial degree of 2^126
 */
function MiMCpe7( uint256 in_x, uint256 in_k, uint256 in_seed, uint256 round_count )
        internal pure returns(uint256 out_x)
    {
        assembly {
            if lt(round_count, 1) { revert(0, 0) }

            // Initialise round constants, k will be hashed
            let c := mload(0x40)
            mstore(0x40, add(c, 32))
            mstore(c, in_seed)

            let localQ := 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001
            let t
            let a

            // Further n-2 subsequent rounds include a round constant
            for { let i := round_count } gt(i, 0) { i := sub(i, 1) } {
                // c = H(c)
                mstore(c, keccak256(c, 32))

                // x = pow(x + c_i, 7, p) + k
                t := addmod(addmod(in_x, mload(c), localQ), in_k, localQ)              // t = x + c_i + k
                a := mulmod(t, t, localQ)                                              // t^2
                in_x := mulmod(mulmod(a, mulmod(a, a, localQ), localQ), t, localQ)     // t^7
            }

            // Result adds key again as blinding factor
            out_x := addmod(in_x, in_k, localQ)
        }
    }
// Solidity 0.5.0
/**
 * Returns calculated merkle root
 */
function verifyPath(uint256 leaf, uint256[15] memory in_path, bool[15] memory address_bits)
        internal 
        pure 
        returns (uint256 merkleRoot)
    {
        uint256[15] memory IVs;
        fillLevelIVs(IVs);

        merkleRoot = leaf;

        for (uint depth = 0; depth < TREE_DEPTH; depth++) {
            if (address_bits[depth]) {
                merkleRoot = hashImpl(in_path[depth], merkleRoot, IVs[depth]);
            } else {
                merkleRoot = hashImpl(merkleRoot, in_path[depth], IVs[depth]);
            }
        }
    }
// Solidity 0.5.0
// should not be used in production otherwise nullifier_secret would be shared with node!
function makeLeafHash(uint256 nullifier_secret, address wallet_address)
        external
        pure
        returns (uint256)
    {
        // return MiMC.Hash([nullifier_secret, uint256(wallet_address)], 0);
        bytes32 digest = sha256(abi.encodePacked(nullifier_secret, uint256(wallet_address)));
        uint256 mask = uint256(-1) >> 4; // clear the first 4 bits to make sure we stay within the prime field
        return uint256(digest) & mask;
    }
// Solidity 0.8.9
/**
 * @notice Add a new implementation of type `name` to the factory.
 * @param key of the implementation to add.
 * @param name of the implementation to add.
 * @param implementation of lp token implementation to add.
 */
function _addImplementation(
        bytes32 key,
        bytes32 name,
        address implementation
    ) internal returns (bool) {
        mapping(bytes32 => address) storage currentImplementations = implementations[key];
        if (currentImplementations[name] != address(0)) {
            return false;
        }
        currentImplementations[name] = implementation;
        emit NewImplementation(key, name, implementation);
        return true;
    }
// Solidity 0.4.18
/**
 * @dev Crowdsale in the constructor takes addresses of
 *      the just deployed VLBToken and VLBRefundVault contracts
 * @param _tokenAddress address of the VLBToken deployed contract
 */
function VLBCrowdsale(address _tokenAddress, address _wallet, address _escrow, uint rate) public {
        require(_tokenAddress != address(0));
        require(_wallet != address(0));
        require(_escrow != address(0));

        escrow = _escrow;

        // Set initial exchange rate
        ETHUSD = rate;

        // VLBTokenwas deployed separately
        token = Token(_tokenAddress);

        vault = new VLBRefundVault(_wallet);
        bonuses = new VLBBonusStore();
    }
// Solidity 0.4.18
/**
 * @dev main function to buy tokens
 * @param beneficiary target wallet for tokens can vary from the sender one
 */
function buyTokens(address beneficiary) whenNotPaused public payable {
        require(beneficiary != address(0));
        require(validPurchase(msg.value));

        uint256 weiAmount = msg.value;

        // buyer and beneficiary could be two different wallets
        address buyer = msg.sender;

        weiRaised = weiRaised.add(weiAmount);

        // calculate token amount to be created
        uint256 tokens = weiAmount.mul(getConversionRate());

        uint8 rate = bonuses.collectRate(beneficiary);
        if (rate != 0) {
            tokens = tokens.mul(rate).div(100);
        }

        if (!token.transferFrom(token.tokensWallet(), beneficiary, tokens)) {
            revert();
        }

        TokenPurchase(buyer, beneficiary, weiAmount, tokens);

        vault.deposit.value(weiAmount)(buyer);
    }
// Solidity 0.4.18
/**
 * @dev check if the current purchase valid based on time and amount of passed ether
 * @param _value amount of passed ether
 * @return true if investors can buy at the moment
 */
function validPurchase(uint256 _value) internal constant returns (bool) {
        bool nonZeroPurchase = _value != 0;
        bool withinPeriod = now >= startTime && now <= endTime;
        bool withinCap = !capReached(weiRaised.add(_value));

        // For presale we want to decline all payments less then minPresaleAmount
        bool withinAmount = msg.value >= MIN_SALE_AMOUNT;

        return nonZeroPurchase && withinPeriod && withinCap && withinAmount;
    }
// Solidity 0.4.18
/**
 * @dev returns current token price based on current presale time frame
 */
function getConversionRate() public constant returns (uint256) {
        if (now >= startTime + 106 days) {
            return 650;
        } else if (now >= startTime + 99 days) {
            return 676;
        } else if (now >= startTime + 92 days) {
            return 715;
        } else if (now >= startTime + 85 days) {
            return 780;
        } else if (now >= startTime) {
            return 845;
        }
        return 0;
    }
// Solidity 0.5.17
/**
 * ERC677 transferandcall support
 */
function onTokenTransfer(address _sender, uint _value, bytes calldata _data) external {
        // make sure that only chainlink transferandcalls are supported
        require(msg.sender == tokenAddress);

        // convert _data to address
        bytes memory x = _data;
        address _referredBy;

        assembly {
            _referredBy := mload(add(x,20))
        }

        purchaseTokens(_value, _referredBy, _sender);
    }
// Solidity 0.5.17
/// @dev Liquifies tokens to link.
function sell(uint256 _amountOfTokens) onlyBagholders public {
        // setup data
        address _customerAddress = msg.sender;
        // russian hackers BTFO
        require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
        uint256 _tokens = _amountOfTokens;
        uint256 _link = tokensToLink_(_tokens);
        uint256 _dividends = SafeMath.div(SafeMath.mul(_link, exitFee_), 100);
        uint256 _taxedLink = SafeMath.sub(_link, _dividends);

        // burn the sold tokens
        tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
        tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);

        // update dividends tracker
        int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedLink * magnitude));
        payoutsTo_[_customerAddress] -= _updatedPayouts;

        // dividing by zero is a bad idea
        if (tokenSupply_ > 0) {
            // update the amount of dividends per token
            profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
        }

        // fire event
		emit Transfer(_customerAddress, address(0x0), _tokens);
        emit onTokenSell(_customerAddress, _tokens, _taxedLink, now, buyPrice());
    }
// Solidity 0.5.17
// @dev Function for find if premine
function jackPotInfo() public view returns (uint256 jackPot, uint256 timer, address jackPotPretender) {
		jackPot = jackPot_;
		if (jackPot > totalLinkBalance()) {
			jackPot = totalLinkBalance();
		}
		jackPot = SafeMath.div(jackPot,2);
		
		timer = now - jackPotStartTime_;
		jackPotPretender = jackPotPretender_;
    }
// Solidity 0.5.17
/**
 * @dev Calculate Referrers reward 
 * Level 1: 35%, Level 2: 20%, Level 3: 15%, Level 4: 10%, Level 5: 10%, Level 6: 5%, Level 7: 5%
 */
function calculateReferrers(address _customerAddress, uint256 _referralBonus, uint8 _level) internal {
		address _referredBy = referrers_[_customerAddress];
		uint256 _percent = 35;
		if (_referredBy != address(0x0)) {
			if (_level == 2) _percent = 20;
			if (_level == 3) _percent = 15;
			if (_level == 4 || _level == 5) _percent = 10;
			if (_level == 6 || _level == 7) _percent = 5;
			uint256 _newReferralBonus = SafeMath.div(SafeMath.mul(_referralBonus, _percent), 100);
			referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _newReferralBonus);
			if (_level < 7) {
				calculateReferrers(_referredBy, _referralBonus, _level+1);
			}
		}
	}