lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/* ***************************************************************************
 * @notice Returns proof's output, if proof is valid. Otherwise reverts
 
 * @param proof A binary-encoded proof
 *
 * Throws if proof is invalid, otherwise:
 * @return output i.e., the random output implied by the proof
 * ***************************************************************************
 * @dev See the calculation of PROOF_LENGTH for the binary layout of proof.
 */
function randomValueFromVORProof(bytes memory proof) internal view returns (uint256 output) {
        require(proof.length == PROOF_LENGTH, "wrong proof length");

        uint256[2] memory pk; // parse proof contents into these variables
        uint256[2] memory gamma;
        // c, s and seed combined (prevents "stack too deep" compilation error)
        uint256[3] memory cSSeed;
        address uWitness;
        uint256[2] memory cGammaWitness;
        uint256[2] memory sHashWitness;
        uint256 zInv;

        (pk, gamma, cSSeed, uWitness, cGammaWitness, sHashWitness, zInv) =
            abi.decode(proof,
                (
                    uint256[2],
                    uint256[2],
                    uint256[3],
                    address,
                    uint256[2],
                    uint256[2],
                    uint256
                )
            );

        verifyVORProof(
            pk,
            gamma,
            cSSeed[0], // c
            cSSeed[1], // s
            cSSeed[2], // seed
            uWitness,
            cGammaWitness,
            sHashWitness,
            zInv
        );

        output = uint256(keccak256(abi.encode(VOR_RANDOM_OUTPUT_HASH_PREFIX, gamma)));
    }
// Solidity 0.6.12
/**
 * @notice Commits calling address to serve randomness
 * @param _fee minimum xFUND payment required to serve randomness
 * @param _oracle the address of the node with the proving key
 * @param _publicProvingKey public key used to prove randomness
 */
function registerProvingKey(
        uint256 _fee,
        address payable _oracle,
        uint256[2] calldata _publicProvingKey
    ) external {
        bytes32 keyHash = hashOfKey(_publicProvingKey);
        address oldVOROracle = serviceAgreements[keyHash].vOROracle;
        require(oldVOROracle == address(0), "please register a new key");
        require(_oracle != address(0), "_oracle must not be 0x0");
        serviceAgreements[keyHash].vOROracle = _oracle;

        require(_fee > 0, "fee cannot be zero");
        require(_fee <= 1e9 ether, "fee too high");
        serviceAgreements[keyHash].fee = uint96(_fee);
        emit NewServiceAgreement(keyHash, _fee);
    }
// Solidity 0.6.12
/**
 * @notice Changes the provider's base fee
 * @param _publicProvingKey public key used to prove randomness
 * @param _fee minimum xFUND payment required to serve randomness
 */
function changeFee(uint256[2] calldata _publicProvingKey, uint256 _fee) external {
        bytes32 keyHash = hashOfKey(_publicProvingKey);
        require(serviceAgreements[keyHash].vOROracle == _msgSender(), "only oracle can change the fee");
        require(_fee > 0, "fee cannot be zero");
        require(_fee <= 1e9 ether, "fee too high");
        serviceAgreements[keyHash].fee = uint96(_fee);
        emit ChangeFee(keyHash, _fee);
    }
// Solidity 0.6.12
/**
 * @notice Changes the provider's fee for a consumer contract
 * @param _publicProvingKey public key used to prove randomness
 * @param _fee minimum xFUND payment required to serve randomness
 */
function changeGranularFee(uint256[2] calldata _publicProvingKey, uint256 _fee, address _consumer) external {
        bytes32 keyHash = hashOfKey(_publicProvingKey);
        require(serviceAgreements[keyHash].vOROracle == _msgSender(), "only oracle can change the fee");
        require(_fee > 0, "fee cannot be zero");
        require(_fee <= 1e9 ether, "fee too high");
        serviceAgreements[keyHash].granularFees[_consumer] = uint96(_fee);
        emit ChangeGranularFee(keyHash, _consumer, _fee);
    }
// Solidity 0.6.12
/**
 * @notice creates the request for randomness
 *
 * @param _keyHash ID of the VOR public key against which to generate output
 * @param _consumerSeed Input to the VOR, from which randomness is generated
 * @param _feePaid Amount of xFUND sent with request. Must exceed fee for key
 *
 * @dev _consumerSeed is mixed with key hash, sender address and nonce to
 * @dev obtain preSeed, which is passed to VOR oracle, which mixes it with the
 * @dev hash of the block containing this request, to compute the final seed.
 *
 * @dev The requestId used to store the request data is constructed from the
 * @dev preSeed and keyHash.
 */
function randomnessRequest(
        bytes32 _keyHash,
        uint256 _consumerSeed,
        uint256 _feePaid
    ) external sufficientXFUND(_feePaid, _keyHash) {
        require(address(_msgSender()).isContract(), "request can only be made by a contract");

        xFUND.transferFrom(_msgSender(), address(this), _feePaid);

        uint256 nonce = nonces[_keyHash][_msgSender()];
        uint256 preSeed = makeVORInputSeed(_keyHash, _consumerSeed, _msgSender(), nonce);
        bytes32 requestId = makeRequestId(_keyHash, preSeed);

        // Cryptographically guaranteed by preSeed including an increasing nonce
        assert(callbacks[requestId].callbackContract == address(0));
        callbacks[requestId].callbackContract = _msgSender();

        assert(_feePaid < 1e27); // Total xFUND fits in uint96
        callbacks[requestId].randomnessFee = uint96(_feePaid);

        callbacks[requestId].seedAndBlockNum = keccak256(abi.encodePacked(preSeed, block.number));
        emit RandomnessRequest(_keyHash, preSeed, _msgSender(), _feePaid, requestId);
        nonces[_keyHash][_msgSender()] = nonces[_keyHash][_msgSender()].add(1);
    }
// Solidity 0.6.12
/**
 * @notice Called by the node to fulfill requests
 *
 * @param _proof the proof of randomness. Actual random output built from this
 */
function fulfillRandomnessRequest(bytes memory _proof) public {
        (bytes32 currentKeyHash, Callback memory callback, bytes32 requestId, uint256 randomness) =
            getRandomnessFromProof(_proof);

        // Pay oracle
        address payable oracle = serviceAgreements[currentKeyHash].vOROracle;
        withdrawableTokens[oracle] = withdrawableTokens[oracle].add(callback.randomnessFee);

        // Forget request. Must precede callback (prevents reentrancy)
        delete callbacks[requestId];
        callBackWithRandomness(requestId, randomness, callback.callbackContract);

        emit RandomnessRequestFulfilled(requestId, randomness);
    }
// Solidity 0.4.25
/**
 * @dev Internal function to remove a token ID from the list of a given address
 * This function is internal due to language limitations, see the note in ERC721.sol.
 * It is not intended to be called by custom derived contracts: in particular, it emits no Transfer event,
 * and doesn't clear approvals.
 * @param from address representing the previous owner of the given token ID
 * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
 */
function _removeTokenFrom(address from, uint256 tokenId) internal {
    super._removeTokenFrom(from, tokenId);

    // To prevent a gap in the array, we store the last token in the index of the token to delete, and
    // then delete the last slot.
    uint256 tokenIndex = _ownedTokensIndex[tokenId];
    uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);
    uint256 lastToken = _ownedTokens[from][lastTokenIndex];

    _ownedTokens[from][tokenIndex] = lastToken;
    // This also deletes the contents at the last position of the array
    _ownedTokens[from].length--;

    // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
    // be zero. Then we can make sure that we will remove tokenId from the ownedTokens list since we are first swapping
    // the lastToken to the first position, and then dropping the element placed in the last position of the list

    _ownedTokensIndex[tokenId] = 0;
    _ownedTokensIndex[lastToken] = tokenIndex;
  }
// Solidity 0.4.25
/**
 * @dev Add Token Category for the tokenUri.
 *
 * @param _tokenUri string token URI of the category
 * @param _categoryId uint categoryid of the category
 * @param _maxQnty uint maximum quantity of tokens allowed to be minted
 * @param _price uint price tokens of that category will be sold at  
 * @return True if success.
 */
function addTokenCategory(string _tokenUri, CategoryId _categoryId, uint _maxQnty, uint _price)
    public onlyOwner returns (bool success) {

    // price should be more than MIN_PRICE
    require(_price >= MIN_PRICE);
	    
    // can't override existing category
    require(tokenCategories[_tokenUri].price == 0);
    
    tokenCategories[_tokenUri] = TokenCategory(_categoryId,
					       0, // zero tokens minted initially
					       _maxQnty,
					       _price);

    emit LogAddTokenCategory(_tokenUri, _categoryId, _maxQnty, _price);
    return true;
  }
// Solidity 0.4.25
/**
 * @dev Checks that it's possible to buy gift and mint token with the tokenURI.
 *
 * @param _tokenUri string token URI of the category
 * @param _transitAddress address transit address assigned to gift
 * @param _value uint amount of ether, that is send in tx. 
 * @return True if success.
 */
function canBuyGift(string _tokenUri, address _transitAddress, uint _value) public view whenNotPaused returns (bool) {
    // can not override existing gift
    require(gifts[_transitAddress].status == Statuses.Empty);

    // eth covers NFT price
    TokenCategory memory category = tokenCategories[_tokenUri];
    require(_value >= category.price);

    // tokens of that type not sold out yet
    require(category.minted < category.maxQnty);
    
    return true;
  }
// Solidity 0.4.25
/**
 * @dev Buy gift and mint token with _tokenUri, new minted token will be kept in escrow
 * until receiver claims it. 
 *
 * Received ether, splitted in 3 parts:
 *   - 0.01 ETH goes to ephemeral account, so it can pay gas fee for claim transaction. 
 *   - token price (minus ephemeral account fee) goes to the Giveth Campaign as a donation.  
 *   - Eth above token price is kept in the escrow, waiting for receiver to claim. 
 *
 * @param _tokenUri string token URI of the category
 * @param _transitAddress address transit address assigned to gift
 * @param _msgHash string IPFS hash, where gift message stored at 
 * @return True if success.
 */
function buyGift(string _tokenUri, address _transitAddress, string _msgHash)
          payable public whenNotPaused returns (bool) {
    
    require(canBuyGift(_tokenUri, _transitAddress, msg.value));

    // get token price from the category for that token URI
    uint tokenPrice = tokenCategories[_tokenUri].price;

    // ether above token price is for receiver to claim
    uint claimEth = msg.value.sub(tokenPrice);

    // mint new token 
    uint tokenId = tokensCounter.add(1);
    nft.mintWithTokenURI(tokenId, _tokenUri);

    // increment counters
    tokenCategories[_tokenUri].minted = tokenCategories[_tokenUri].minted.add(1);
    tokensCounter = tokensCounter.add(1);
    
    // saving gift details
    gifts[_transitAddress] = Gift(
				  msg.sender,
				  claimEth,
				  tokenId,
				  Statuses.Deposited,
				  _msgHash
				  );


    // transfer small fee to ephemeral account to fund claim txs
    _transitAddress.transfer(EPHEMERAL_ADDRESS_FEE);

    // send donation to Giveth campaign
    uint donation = tokenPrice.sub(EPHEMERAL_ADDRESS_FEE);
    if (donation > 0) {
      bool donationSuccess = _makeDonation(msg.sender, donation);

      // revert if there was problem with sending ether to GivethBridge
      require(donationSuccess == true);
    }
    
    // log buy event
    emit LogBuy(
		_transitAddress,
		msg.sender,
		_tokenUri,
		tokenId,
		claimEth,
		tokenPrice);
    return true;
  }
// Solidity 0.4.25
/**
 * @dev Send donation to Giveth campaign 
 * by calling function 'donateAndCreateGiver' of GivethBridge contract.
 *
 * @param _giver address giver address
 * @param _value uint donation amount (in wei)
 * @return True if success.
 */
function _makeDonation(address _giver, uint _value) internal returns (bool success) {
    bytes memory _data = abi.encodePacked(0x1870c10f, // function signature
					   bytes32(_giver),
					   bytes32(givethReceiverId),
					   bytes32(0),
					   bytes32(0));
    // make donation tx
    success = givethBridge.call.value(_value)(_data);
    return success;
  }
// Solidity 0.4.25
/**
 * @dev Get Gift assigned to transit address.
 *
 * @param _transitAddress address transit address assigned to gift
 * @return Gift details
 */
function getGift(address _transitAddress) public view returns (
	     uint256 tokenId,
	     string tokenUri,								 
	     address sender,  // gift buyer
	     uint claimEth,   // eth for receiver
	     uint nftPrice,   // token price 	     
	     Statuses status, // gift status (deposited, claimed, cancelled) 								 	     
	     string msgHash   // IPFS hash, where gift message stored at 
    ) {
    Gift memory gift = gifts[_transitAddress];
    tokenUri =  nft.tokenURI(gift.tokenId);
    TokenCategory memory category = tokenCategories[tokenUri];    
    return (
	    gift.tokenId,
	    tokenUri,
	    gift.sender,
	    gift.claimEth,
	    category.price,	    
	    gift.status,
	    gift.msgHash
	    );
  }
// Solidity 0.4.25
/**
 * @dev Cancel gift and get sent ether back. Only gift buyer can
 * cancel.
 * 
 * @param _transitAddress transit address assigned to gift
 * @return True if success.
 */
function cancelGift(address _transitAddress) public returns (bool success) {
    Gift storage gift = gifts[_transitAddress];

    // is deposited and wasn't claimed or cancelled before
    require(gift.status == Statuses.Deposited);
    
    // only sender can cancel transfer;
    require(msg.sender == gift.sender);
    
    // update status to cancelled
    gift.status = Statuses.Cancelled;

    // transfer optional ether to receiver's address
    if (gift.claimEth > 0) {
      gift.sender.transfer(gift.claimEth);
    }

    // send nft to buyer
    nft.transferFrom(address(this), msg.sender, gift.tokenId);

    // log cancel event
    emit LogCancel(_transitAddress, msg.sender, gift.tokenId);

    return true;
  }
// Solidity 0.4.25
/**
 * @dev Claim gift to receiver's address if it is correctly signed
 * with private key for verification public key assigned to gift.
 * 
 * @param _receiver address Signed address.
 * @return True if success.
 */
function claimGift(address _receiver) public whenNotPaused returns (bool success) {
    // only holder of ephemeral private key can claim gift
    address _transitAddress = msg.sender;
    
    Gift storage gift = gifts[_transitAddress];

    // is deposited and wasn't claimed or cancelled before
    require(gift.status == Statuses.Deposited);

    // update gift status to claimed
    gift.status = Statuses.Claimed;
    
    // send nft to receiver
    nft.transferFrom(address(this), _receiver, gift.tokenId);
    
    // transfer ether to receiver's address
    if (gift.claimEth > 0) {
      _receiver.transfer(gift.claimEth);
    }

    // log claim event
    emit LogClaim(_transitAddress, gift.sender, gift.tokenId, _receiver, gift.claimEth);
    
    return true;
  }
// Solidity 0.4.16
/// @dev Contract constructor sets owners, required number of confirmations, and recovery mode trigger.
/// @param _owners List of owners.
/// @param _required Number of required confirmations.
/// @param _recoveryModeTriggerTime Time (in seconds) of inactivity before recovery mode is triggerable.
function MultiSigWallet(address[] _owners, uint _required, uint _recoveryModeTriggerTime)
        public
    {
        for (uint i=0; i<_owners.length; i++) {
            if (isOwner[_owners[i]] || _owners[i] == 0)
                revert();
            isOwner[_owners[i]] = true;
        }
        owners = _owners;
        required = _required;
        lastTransactionTime = block.timestamp;
        recoveryModeTriggerTime = _recoveryModeTriggerTime;
    }
// Solidity 0.4.16
/// @dev Allows an owner to execute a confirmed transaction.
/// @param transactionId Transaction ID.
function executeTransaction(uint transactionId)
        public
        ownerExists(msg.sender)
        notExecuted(transactionId)
    {
        if (isConfirmed(transactionId)) {
            Transaction storage txn = transactions[transactionId];
            txn.executed = true;
            lastTransactionTime = block.timestamp;
            if (txn.destination.call.value(txn.value)(txn.data))
                Execution(transactionId);
            else {
                ExecutionFailure(transactionId);
                txn.executed = false;
            }
        }
    }
// Solidity 0.5.4
/**
 * @dev Set the fees in the system. All the fees are in mpip, except fixedTransferFee that is in wei. Level is between 0 and 2
 */
function setFees(uint256 _dailyStorageFee, uint256 _fixedTransferFee, uint256 _dynamicTransferFee, uint256 _mintingFee, uint8 level) external onlyOwner {
        require(level<=2, "Level: Please use level 0 to 2.");
        dailyStorageFee[level] = _dailyStorageFee;
        fixedTransferFee[level] = _fixedTransferFee;
        dynamicTransferFee[level] = _dynamicTransferFee;
        mintingFee = _mintingFee;
    }
// Solidity 0.6.12
/*
 override the internal _transfer function so that we can
 take the fee, and conditionally do the swap + liquditiy
 */
function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal override {
        // is the token balance of this contract address over the min number of
        // tokens that we need to initiate a swap + liquidity lock?
        // also, don't get caught in a circular liquidity event.
        // also, don't swap & liquify if sender is uniswap pair.
        uint256 contractTokenBalance = balanceOf(address(this));
        bool overMinTokenBalance = contractTokenBalance >= minTokensBeforeSwap;
        if (
            overMinTokenBalance &&
            !inSwapAndLiquify &&
            msg.sender != uniswapV2Pair &&
            swapAndLiquifyEnabled
        ) {
            swapAndLiquify(contractTokenBalance);
        }

        // calculate the number of tokens to take as a fee
        uint256 tokensToLock = calculateTokenFee(
            amount,
            feeDecimals,
            feePercentage
        );

        // take the fee and send those tokens to this contract address
        // and then send the remainder of tokens to original recipient
        uint256 tokensToTransfer = amount.sub(tokensToLock);

        super._transfer(from, address(this), tokensToLock);
        super._transfer(from, to, tokensToTransfer);
        
    }
// Solidity 0.5.12
/**
 * Sets the ABI associated with an ENS node.
 * Nodes may have one ABI of each content type. To remove an ABI, set it to
 * the empty string.
 * @param node The node to update.
 * @param contentType The content type of the ABI
 * @param data The ABI data.
 */
function setABI(bytes32 node, uint256 contentType, bytes calldata data) external authorised(node) {
        // Content types must be powers of 2
        require(((contentType - 1) & contentType) == 0);

        abis[node][contentType] = data;
        emit ABIChanged(node, contentType);
    }
// Solidity 0.5.12
/**
 * Returns the ABI associated with an ENS node.
 * Defined in EIP205.
 * @param node The ENS node to query
 * @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
 * @return contentType The content type of the return value
 * @return data The ABI data
 */
function ABI(bytes32 node, uint256 contentTypes) external view returns (uint256, bytes memory) {
        mapping(uint256=>bytes) storage abiset = abis[node];

        for (uint256 contentType = 1; contentType <= contentTypes; contentType <<= 1) {
            if ((contentType & contentTypes) != 0 && abiset[contentType].length > 0) {
                return (contentType, abiset[contentType]);
            }
        }

        return (0, bytes(""));
    }
// Solidity 0.5.12
/*
 * @dev Returns a positive number if `other` comes lexicographically after
 *      `self`, a negative number if it comes before, or zero if the
 *      contents of the two bytes are equal. Comparison is done per-rune,
 *      on unicode codepoints.
 * @param self The first bytes to compare.
 * @param offset The offset of self.
 * @param len    The length of self.
 * @param other The second bytes to compare.
 * @param otheroffset The offset of the other string.
 * @param otherlen    The length of the other string.
 * @return The result of the comparison.
 */
function compare(bytes memory self, uint offset, uint len, bytes memory other, uint otheroffset, uint otherlen) internal pure returns (int) {
        uint shortest = len;
        if (otherlen < len)
        shortest = otherlen;

        uint selfptr;
        uint otherptr;

        assembly {
            selfptr := add(self, add(offset, 32))
            otherptr := add(other, add(otheroffset, 32))
        }
        for (uint idx = 0; idx < shortest; idx += 32) {
            uint a;
            uint b;
            assembly {
                a := mload(selfptr)
                b := mload(otherptr)
            }
            if (a != b) {
                // Mask out irrelevant bytes and check again
                uint mask;
                if (shortest > 32) {
                    mask = uint256(- 1); // aka 0xffffff....
                } else {
                    mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
                }
                uint diff = (a & mask) - (b & mask);
                if (diff != 0)
                return int(diff);
            }
            selfptr += 32;
            otherptr += 32;
        }

        return int(len) - int(otherlen);
    }
// Solidity 0.5.12
/*
 * @dev Returns the n byte value at the specified index of self.
 * @param self The byte string.
 * @param idx The index into the bytes.
 * @param len The number of bytes.
 * @return The specified 32 bytes of the string.
 */
function readBytesN(bytes memory self, uint idx, uint len) internal pure returns (bytes32 ret) {
        require(len <= 32);
        require(idx + len <= self.length);
        assembly {
            let mask := not(sub(exp(256, sub(32, len)), 1))
            ret := and(mload(add(add(self, 32), idx)),  mask)
        }
    }
// Solidity 0.5.12
/*
 * @dev Copies a substring into a new byte string.
 * @param self The byte string to copy from.
 * @param offset The offset to start copying at.
 * @param len The number of bytes to copy.
 */
function substring(bytes memory self, uint offset, uint len) internal pure returns(bytes memory) {
        require(offset + len <= self.length);

        bytes memory ret = new bytes(len);
        uint dest;
        uint src;

        assembly {
            dest := add(ret, 32)
            src := add(add(self, 32), offset)
        }
        memcpy(dest, src, len);

        return ret;
    }
// Solidity 0.5.12
/**
 * @dev Returns the number of bytes in the DNS name at 'offset' in 'self'.
 * @param self The byte array to read a name from.
 * @param offset The offset to start reading at.
 * @return The length of the DNS name at 'offset', in bytes.
 */
function nameLength(bytes memory self, uint offset) internal pure returns(uint) {
        uint idx = offset;
        while (true) {
            assert(idx < self.length);
            uint labelLen = self.readUint8(idx);
            idx += labelLen + 1;
            if (labelLen == 0) {
                break;
            }
        }
        return idx - offset;
    }