lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 @notice Reveals vote with choice and secret salt used in generating commitHash to attribute committed tokens
 @param _pollID Integer identifier associated with target poll
 @param _voteOption Vote choice used to generate commitHash for associated poll
 @param _salt Secret number used to generate commitHash for associated poll
 */
function revealVote(uint _pollID, uint _voteOption, uint _salt) public {
        // Make sure the reveal period is active
        require(revealPeriodActive(_pollID));
        require(pollMap[_pollID].didCommit[msg.sender]);                         // make sure user has committed a vote for this poll
        require(!pollMap[_pollID].didReveal[msg.sender]);                        // prevent user from revealing multiple times
        require(keccak256(abi.encodePacked(_voteOption, _salt)) == getCommitHash(msg.sender, _pollID)); // compare resultant hash from inputs to original commitHash

        uint numTokens = getNumTokens(msg.sender, _pollID);

        if (_voteOption == 1) {// apply numTokens to appropriate poll choice
            pollMap[_pollID].votesFor += numTokens;
        } else {
            pollMap[_pollID].votesAgainst += numTokens;
        }

        dllMap[msg.sender].remove(_pollID); // remove the node referring to this vote upon reveal
        pollMap[_pollID].didReveal[msg.sender] = true;
        pollMap[_pollID].voteOptions[msg.sender] = _voteOption;

        emit _VoteRevealed(_pollID, numTokens, pollMap[_pollID].votesFor, pollMap[_pollID].votesAgainst, _voteOption, msg.sender, _salt);
    }
// Solidity 0.4.24
/**
 @notice             Reveals multiple votes with choices and secret salts used in generating commitHashes to attribute committed tokens
 @param _pollIDs     Array of integer identifiers associated with target polls
 @param _voteOptions Array of vote choices used to generate commitHashes for associated polls
 @param _salts       Array of secret numbers used to generate commitHashes for associated polls
 */
function revealVotes(uint[] _pollIDs, uint[] _voteOptions, uint[] _salts) external {
        // make sure the array lengths are all the same
        require(_pollIDs.length == _voteOptions.length);
        require(_pollIDs.length == _salts.length);

        // loop through arrays, revealing each individual vote values
        for (uint i = 0; i < _pollIDs.length; i++) {
            revealVote(_pollIDs[i], _voteOptions[i], _salts[i]);
        }
    }
// Solidity 0.4.24
/**
 @param _voter           Address of voter who voted in the majority bloc
 @param _pollID          Integer identifier associated with target poll
 @return correctVotes    Number of tokens voted for winning option
 */
function getNumPassingTokens(address _voter, uint _pollID) public constant returns (uint correctVotes) {
        require(pollEnded(_pollID));
        require(pollMap[_pollID].didReveal[_voter]);

        uint winningChoice = isPassed(_pollID) ? 1 : 0;
        uint voterVoteOption = pollMap[_pollID].voteOptions[_voter];

        require(voterVoteOption == winningChoice, "Voter revealed, but not in the majority");

        return getNumTokens(_voter, _pollID);
    }
// Solidity 0.4.24
/**
 @dev Initiates a poll with canonical configured parameters at pollID emitted by PollCreated event
 @param _voteQuorum Type of majority (out of 100) that is necessary for poll to be successful
 @param _commitDuration Length of desired commit period in seconds
 @param _revealDuration Length of desired reveal period in seconds
 */
function startPoll(uint _voteQuorum, uint _commitDuration, uint _revealDuration) public returns (uint pollID) {
        pollNonce = pollNonce + 1;

        uint commitEndDate = block.timestamp.add(_commitDuration);
        uint revealEndDate = commitEndDate.add(_revealDuration);

        pollMap[pollNonce] = Poll({
            voteQuorum: _voteQuorum,
            commitEndDate: commitEndDate,
            revealEndDate: revealEndDate,
            votesFor: 0,
            votesAgainst: 0
        });

        emit _PollCreated(_voteQuorum, commitEndDate, revealEndDate, pollNonce, msg.sender);
        return pollNonce;
    }
// Solidity 0.4.24
/*
 @dev Takes the last node in the user's DLL and iterates backwards through the list searching
 for a node with a value less than or equal to the provided _numTokens value. When such a node
 is found, if the provided _pollID matches the found nodeID, this operation is an in-place
 update. In that case, return the previous node of the node being updated. Otherwise return the
 first node that was found with a value less than or equal to the provided _numTokens.
 @param _voter The voter whose DLL will be searched
 @param _numTokens The value for the numTokens attribute in the node to be inserted
 @return the node which the propoded node should be inserted after
 */
function getInsertPointForNumTokens(address _voter, uint _numTokens, uint _pollID)
    constant public returns (uint prevNode) {
        // Get the last node in the list and the number of tokens in that node
        uint nodeID = getLastNode(_voter);
        uint tokensInNode = getNumTokens(_voter, nodeID);

        // Iterate backwards through the list until reaching the root node
        while(nodeID != 0) {
            // Get the number of tokens in the current node
            tokensInNode = getNumTokens(_voter, nodeID);
            if(tokensInNode <= _numTokens) { // We found the insert point!
                if(nodeID == _pollID) {
                    // This is an in-place update. Return the prev node of the node being updated
                    nodeID = dllMap[_voter].getPrev(nodeID);
                }
                // Return the insert point
                return nodeID;
            }
            // We did not find the insert point. Continue iterating backwards through the list
            nodeID = dllMap[_voter].getPrev(nodeID);
        }

        // The list is empty, or a smaller value than anything else in the list is being inserted
        return nodeID;
    }
// Solidity 0.4.24
/**
 @notice propose a reparamaterization of the key _name's value to _value.
 @param _name the name of the proposed param to be set
 @param _value the proposed value to set the param to be set
 */
function proposeReparameterization(string _name, uint _value) public returns (bytes32) {
        uint deposit = get("pMinDeposit");
        bytes32 propID = keccak256(abi.encodePacked(_name, _value));

        if (keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("dispensationPct")) ||
            keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("pDispensationPct"))) {
            require(_value <= 100);
        }

        require(!propExists(propID)); // Forbid duplicate proposals
        require(get(_name) != _value); // Forbid NOOP reparameterizations

        // attach name and value to pollID
        proposals[propID] = ParamProposal({
            appExpiry: now.add(get("pApplyStageLen")),
            challengeID: 0,
            deposit: deposit,
            name: _name,
            owner: msg.sender,
            processBy: now.add(get("pApplyStageLen"))
                .add(get("pCommitStageLen"))
                .add(get("pRevealStageLen"))
                .add(PROCESSBY),
            value: _value
        });

        require(token.transferFrom(msg.sender, this, deposit)); // escrow tokens (deposit amt)

        emit _ReparameterizationProposal(_name, _value, propID, deposit, proposals[propID].appExpiry, msg.sender);
        return propID;
    }
// Solidity 0.4.24
/**
 @notice challenge the provided proposal ID, and put tokens at stake to do so.
 @param _propID the proposal ID to challenge
 */
function challengeReparameterization(bytes32 _propID) public returns (uint challengeID) {
        ParamProposal memory prop = proposals[_propID];
        uint deposit = prop.deposit;

        require(propExists(_propID) && prop.challengeID == 0);

        //start poll
        uint pollID = voting.startPoll(
            get("pVoteQuorum"),
            get("pCommitStageLen"),
            get("pRevealStageLen")
        );

        challenges[pollID] = Challenge({
            challenger: msg.sender,
            rewardPool: SafeMath.sub(100, get("pDispensationPct")).mul(deposit).div(100),
            stake: deposit,
            resolved: false,
            winningTokens: 0
        });

        proposals[_propID].challengeID = pollID;       // update listing to store most recent challenge

        //take tokens from challenger
        require(token.transferFrom(msg.sender, this, deposit));

        (uint commitEndDate, uint revealEndDate,,,) = voting.pollMap(pollID);

        emit _NewChallenge(_propID, pollID, commitEndDate, revealEndDate, msg.sender);
        return pollID;
    }
// Solidity 0.4.24
/**
 @notice                 Claim the tokens owed for the msg.sender in the provided challenge
 @param _challengeID     the challenge ID to claim tokens for
 */
function claimReward(uint _challengeID) public {
        Challenge storage challenge = challenges[_challengeID];
        // ensure voter has not already claimed tokens and challenge results have been processed
        require(challenge.tokenClaims[msg.sender] == false);
        require(challenge.resolved == true);

        uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID);
        uint reward = voterReward(msg.sender, _challengeID);

        // subtract voter's information to preserve the participation ratios of other voters
        // compared to the remaining pool of rewards
        challenge.winningTokens -= voterTokens;
        challenge.rewardPool -= reward;

        // ensures a voter cannot claim tokens again
        challenge.tokenClaims[msg.sender] = true;

        emit _RewardClaimed(_challengeID, reward, msg.sender);
        require(token.transfer(msg.sender, reward));
    }
// Solidity 0.4.24
/**
 @notice Determines the number of tokens to awarded to the winning party in a challenge
 @param _challengeID The challengeID to determine a reward for
 */
function challengeWinnerReward(uint _challengeID) public view returns (uint) {
        if(voting.getTotalNumberOfTokensForWinningOption(_challengeID) == 0) {
            // Edge case, nobody voted, give all tokens to the challenger.
            return 2 * challenges[_challengeID].stake;
        }

        return (2 * challenges[_challengeID].stake) - challenges[_challengeID].rewardPool;
    }
// Solidity 0.4.24
/**
 @dev resolves a challenge for the provided _propID. It must be checked in advance whether the _propID has a challenge on it
 @param _propID the proposal ID whose challenge is to be resolved.
 */
function resolveChallenge(bytes32 _propID) private {
        ParamProposal memory prop = proposals[_propID];
        Challenge storage challenge = challenges[prop.challengeID];

        // winner gets back their full staked deposit, and dispensationPct*loser's stake
        uint reward = challengeWinnerReward(prop.challengeID);

        challenge.winningTokens = voting.getTotalNumberOfTokensForWinningOption(prop.challengeID);
        challenge.resolved = true;

        if (voting.isPassed(prop.challengeID)) { // The challenge failed
            if(prop.processBy > now) {
                set(prop.name, prop.value);
            }
            emit _ChallengeFailed(_propID, prop.challengeID, challenge.rewardPool, challenge.winningTokens);
            require(token.transfer(prop.owner, reward));
        }
        else { // The challenge succeeded or nobody voted
            emit _ChallengeSucceeded(_propID, prop.challengeID, challenge.rewardPool, challenge.winningTokens);
            require(token.transfer(challenges[prop.challengeID].challenger, reward));
        }
    }
// Solidity 0.4.26
/**
 * @dev override transferFrom token for a specified address to add validDestination
 * @param _from The address to transfer from.
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 */
function transferFrom(address _from, address _to, uint256 _value)
    onlyPayloadSize(32 + 32 + 32) // address (32) + address (32) + uint256 (32)
    validDestination(_to)
    onlyWhenTransferEnabled
    public
    returns (bool)
  {
    return super.transferFrom(_from, _to, _value);
  }
// Solidity 0.4.24
// can never adjust tradable cards
// each season gets a 'balancing beta'
// totally immutable: season, rarity
function replaceProto(
        uint16 index, uint8 god, uint8 cardType, uint8 mana, uint8 attack, uint8 health, uint8 tribe
    ) public onlyGovernor {
        ProtoCard memory pc = protos[index];
        require(!seasonTradable[pc.season]);
        protos[index] = ProtoCard({
            exists: true,
            god: god,
            season: pc.season,
            cardType: cardType,
            rarity: pc.rarity,
            mana: mana,
            attack: attack,
            health: health,
            tribe: tribe
        });
    }
// Solidity 0.4.24
/**
 * @param proposed : the claimed owner of the cards
 * @param ids : the ids of the cards to check
 * @return whether proposed owns all of the cards 
 */
function ownsAll(address proposed, uint[] ids) public view returns (bool) {
        for (uint i = 0; i < ids.length; i++) {
            if (!owns(proposed, ids[i])) {
                return false;
            }
        }
        return true;
    }
// Solidity 0.4.24
/**
 * @param id : the index of the token to burn
 */
function burn(uint id) public {
        // require(isTradable(cards[id].proto));
        require(owns(msg.sender, id));
        burnCount++;
        // use the internal transfer function as the external
        // has a guard to prevent transfers to 0x0
        _transfer(msg.sender, address(0), id);
    }
// Solidity 0.4.24
/**
 * @param to : the address to which the token should be transferred
 * @param id : the index of the token to transfer
 */
function transferFrom(address from, address to, uint id) public payable {
        
        require(to != address(0));
        require(to != address(this));

        // TODO: why is this necessary
        // if you're approved, why does it matter where it comes from?
        require(ownerOf(id) == from);

        require(isSenderApprovedFor(id));

        require(isTradable(cards[id].proto));

        _transfer(ownerOf(id), to, id);
    }
// Solidity 0.4.24
// store purity and shine as one number to save users gas
function _getPurity(uint16 randOne, uint16 randTwo) internal pure returns (uint16) {
        if (randOne >= 998) {
            return 3000 + randTwo;
        } else if (randOne >= 988) {
            return 2000 + randTwo;
        } else if (randOne >= 938) {
            return 1000 + randTwo;
        } else {
            return randTwo;
        }
    }
// Solidity 0.4.24
// can be called by anybody
function callback(uint id) public {

        Purchase storage p = purchases[id];

        require(p.randomness == 0);

        bytes32 bhash = blockhash(p.commit);

        uint random = uint(keccak256(abi.encodePacked(totalCount, bhash)));

        totalCount += p.count;

        if (uint(bhash) == 0) {
            // should never happen (must call within next 256 blocks)
            // if it does, just give them 1: will become common and therefore less valuable
            // set to 1 rather than 0 to avoid calling claim before randomness
            p.randomness = 1;
        } else {
            p.randomness = random;
        }

        emit RandomnessReceived(id, p.user, p.count, p.randomness);
    }
// Solidity 0.8.4
// Get all tiers
function getAllTiers() external view returns (Tier[] memory) {
    Tier[] memory tiers = new Tier[](numTiers);
    for (uint256 i = 1; i < numTiers + 1; i++) {
      tiers[i - 1] = allTiers[i];
    }
    return tiers;
  }
// Solidity 0.8.4
// Before all token transfer
function _beforeTokenTransfer(
    address _from,
    address _to,
    uint256 _tokenId
  ) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) {
    // Store token last transfer timestamp by id
    tokenLastTransferredAt[_tokenId] = block.timestamp;

    // TODO: update tracker of from/to owned tokenIds

    super._beforeTokenTransfer(_from, _to, _tokenId);
  }
// Solidity 0.8.9
/// @notice Check if the index has been marked as claimed.
/// @param index - the index to check
/// @return true if index has been marked as claimed.
function isClaimed(uint256 index) public view returns (bool) {
        uint256 claimedWordIndex = index / 256;
        uint256 claimedBitIndex = index % 256;
        uint256 claimedWord = claimedBitMap[week][claimedWordIndex];
        uint256 mask = (1 << claimedBitIndex);
        return claimedWord & mask == mask;
    }
// Solidity 0.8.9
/// @notice Claim the given amount of the token to the given address.
/// Reverts if the inputs are invalid.
/// @param index - claimer index
/// @param account - claimer account
/// @param amount - claim amount
/// @param merkleProof - merkle proof for the claim
/// @param option - claiming option
function claim(
        uint256 index,
        address account,
        uint256 amount,
        bytes32[] calldata merkleProof,
        Option option
    ) external nonReentrant {
        require(!frozen, "Claiming is frozen.");
        require(!isClaimed(index), "Drop already claimed.");

        // Verify the merkle proof.
        bytes32 node = keccak256(abi.encodePacked(index, account, amount));
        require(
            MerkleProof.verify(merkleProof, merkleRoot, node),
            "Invalid proof."
        );

        // Mark it claimed and send the token.
        _setClaimed(index);

        if (option == Option.ClaimAsCRV) {
            _swapCvxCrvToCrv(amount, account);
        } else if (option == Option.ClaimAsETH) {
            uint256 _crvBalance = _swapCvxCrvToCrv(amount, address(this));
            uint256 _ethAmount = _swapCrvToEth(_crvBalance);
            (bool success, ) = account.call{value: _ethAmount}("");
            require(success, "ETH transfer failed");
        } else if (option == Option.ClaimAsCVX) {
            uint256 _crvBalance = _swapCvxCrvToCrv(amount, address(this));
            uint256 _ethAmount = _swapCrvToEth(_crvBalance);
            uint256 _cvxAmount = _swapEthToCvx(_ethAmount);
            IERC20(CVX_TOKEN).safeTransfer(account, _cvxAmount);
        } else if (option == Option.ClaimAndStake) {
            require(cvxCrvStaking.stakeFor(account, amount), "Staking failed");
        } else {
            IERC20(token).safeTransfer(account, amount);
        }

        emit Claimed(index, amount, account, week, option);
    }
// Solidity 0.8.9
/// @notice Update the merkle root and increment the week.
/// @param _merkleRoot - the new root to push
function updateMerkleRoot(bytes32 _merkleRoot) public onlyAdmin {
        require(frozen, "Contract not frozen.");

        // Increment the week (simulates the clearing of the claimedBitMap)
        week = week + 1;
        // Set the new merkle root
        merkleRoot = _merkleRoot;

        emit MerkleRootUpdated(merkleRoot, week);
    }
// Solidity 0.4.11
///@notice Transfer tokens between accounts
///@param  from The benefactor/sender account.
///@param  to The beneficiary account
///@param  value The amount to be transfered  
function transferFrom(address from, address to, uint value) returns (bool success){
        
        require(
            allowance[from][msg.sender] >= value
            &&balances[from] >= value
            && value > 0
            );
            
            balances[from] = balances[from].sub(value);
            balances[to] =  balances[to].add(value);
            allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
            return true;
        }
// Solidity 0.4.11
///@notice Transfer tokens to the beneficiary account
///@param  to The beneficiary account
///@param  value The amount of tokens to be transfered 
function transfer(address to, uint value) returns (bool success){
        require(
            balances[msg.sender] >= value 
            && value > 0 
            && (!frozenAccount[msg.sender]) 										// Allow transfer only if account is not frozen
            );
            balances[msg.sender] = balances[msg.sender].sub(value);                 
            balances[to] = balances[to].add(value);                               // Update the balance of beneficiary account
			Transfer(msg.sender,to,value);
            return true;
    }
// Solidity 0.4.11
///@notice Increase the number of coins
///@param  target The address of the account where the coins would be added.
///@param  mintedAmount The amount of coins to be added
function mintToken(address target, uint256 mintedAmount) onlyOwner {
        balances[target] = balances[target].add(mintedAmount);      //Add the amount of coins to be increased to the balance
        currentSupply = currentSupply.add(mintedAmount);            //Add the amount of coins to be increased to the supply
        Transfer(0, this, mintedAmount);
        Transfer(this, target, mintedAmount);
    }
// Solidity 0.4.24
/// Notice - Maximum length for _source will be 32 chars otherwise returned bytes32 value will have lossy value.
function bytesToBytes32(bytes _b, uint _offset) internal pure returns (bytes32) {
        bytes32 result;

        for (uint i = 0; i < _b.length; i++) {
            result |= bytes32(_b[_offset + i] & 0xFF) >> (i * 8);
        }
        return result;
    }
// Solidity 0.4.24
/**
 * @notice Changes the bytes32 into string
 * @param _source that need to convert into string
 */
function bytes32ToString(bytes32 _source) internal pure returns (string result) {
        bytes memory bytesString = new bytes(32);
        uint charCount = 0;
        for (uint j = 0; j < 32; j++) {
            byte char = byte(bytes32(uint(_source) * 2 ** (8 * j)));
            if (char != 0) {
                bytesString[charCount] = char;
                charCount++;
            }
        }
        bytes memory bytesStringTrimmed = new bytes(charCount);
        for (j = 0; j < charCount; j++) {
            bytesStringTrimmed[j] = bytesString[j];
        }
        return string(bytesStringTrimmed);
    }
// Solidity 0.4.24
/**
 * @notice Gets function signature from _data
 * @param _data Passed data
 * @return bytes4 sig
 */
function getSig(bytes _data) internal pure returns (bytes4 sig) {
        uint len = _data.length < 4 ? _data.length : 4;
        for (uint i = 0; i < len; i++) {
            sig = bytes4(uint(sig) + uint(_data[i]) * (2 ** (8 * (len - 1 - i))));
        }
    }
// Solidity 0.4.24
/**
 * @notice Validates permissions with PermissionManager if it exists. If there's no permission return false
 * @dev Note that IModule withPerm will allow ST owner all permissions by default
 * @dev this allows individual modules to override this logic if needed (to not allow ST owner all permissions)
 * @param _modules is the modules to check permissions on
 * @param _delegate is the address of the delegate
 * @param _module is the address of the PermissionManager module
 * @param _perm is the permissions data
 * @return success
 */
function checkPermission(address[] storage _modules, address _delegate, address _module, bytes32 _perm) public view returns(bool) {
        if (_modules.length == 0) {
            return false;
        }

        for (uint8 i = 0; i < _modules.length; i++) {
            if (IPermissionManager(_modules[i]).checkPermission(_delegate, _module, _perm)) {
                return true;
            }
        }

        return false;
    }