<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>PWNING</title>
        <link>https://paragraph.com/@pwning-2</link>
        <description>the newest pwn star on the block(chain)!</description>
        <lastBuildDate>Tue, 13 Oct 2026 21:49:17 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>PWNING</title>
            <url>https://storage.googleapis.com/papyrus_images/b09b561b439c282314a3e059058668b74f598d934fe58a578639660f87a47d1e.jpg</url>
            <link>https://paragraph.com/@pwning-2</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Could Wrapped Tokens Like WETH Be (forced) Insolvent?]]></title>
            <link>https://paragraph.com/@pwning-2/could-wrapped-tokens-like-weth-be-forced-insolvent</link>
            <guid>HcOHR2pBprsSzALHt82o</guid>
            <pubDate>Fri, 02 Dec 2022 08:15:11 GMT</pubDate>
            <description><![CDATA[People are joking around the seeming depegging of WETH. The wrapped ETH token contract, the most simple and fundamental contract in the Ethereum ecosystem, is used in almost every DeFi protocol. If the depegging happens, the empire of Ethereum will collapse. Trust me, the depegging of WETH is the last thing you should worry about in Ethereum. Because when that happens, both your ETH and WETH would be worthless. Will we see the doomsday of Ethereum? What if a catastrophic vulnerability is disc...]]></description>
            <content:encoded><![CDATA[<p>People are joking around the seeming depegging of WETH. The wrapped ETH token contract, the most simple and fundamental contract in the Ethereum ecosystem, is used in almost every DeFi protocol. If the depegging happens, the empire of Ethereum will collapse. Trust me, the depegging of WETH is the last thing you should worry about in Ethereum. Because when that happens, both your ETH and WETH would be worthless.</p><p>Will we see the doomsday of Ethereum? What if a catastrophic vulnerability is discovered and exploited in the Ethereum network? Considering the security model of Ethereum, I don’t think that could happen. The execution of smart contracts and the consensus of the network are implemented in multiple independent software clients, a single flaw or discrepancy that affects a minority of the clients will be discarded by the network. Even if we see a nuclear-level bug that destroys all the Ethereum nodes, the community can always fork a new secured chain as the canonical Ethereum, like we have done in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://ethereum.org/en/governance/#dao-fork">the DAO fork</a>.</p><p>However, not all EVM compatible chains are guarded at the same security level and with the same decentralization as Ethereum. In fact, most “Ethereum killer” chains only have one single implementation of their protocol. The lack of diversity is the Achilles’ heel of public chains: if anything goes wrong in their official implementation, the giant will be knocked down easily.</p><p>A few months ago, I found a critical vulnerability in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/paritytech/frontier">paritytech/frontier</a>, an EVM implementation written in rust and mainly used in Polkadot parachains. When I was writing my <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://pwning.mirror.xyz/okyEG4lahAuR81IMabYL5aUdvAsZ8cRCbYBXh8RHFuE">previous blog post</a>, I decided to take one more quick review of the code used in the Moonbeam network, in case I missed anything trivial but critical. My hacker instinct led me to a tricky integer truncation bug!</p><p>Frontier executes normal Ethereum smart contracts, but uses a Polkadot substrate as the ledger. This has a quirk: while balance amounts are 256 bit integers in normal Ethereum, the currency in the Polkadot substrate is only 128 bit. To convert to Polkadot, frontier truncates the 256 bit transfer balance amount to 128 bits. This is the code that handles value transferring in the frontier EVM:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0887d96ecc864d4833f2a889d25de096dd86b80152a4d1baf682a10bbc0efe90.png" alt="frontier/frame/evm/src/runner/stack.rs" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">frontier/frame/evm/src/runner/stack.rs</figcaption></figure><p>Since the balance can never be greater than 128 bit, and the transfer will be validated by the balance substrate eventually, what could go wrong?</p><p>The key is that the <code>transfer.value</code> here, or <code>msg.value</code> in EVM, is a totally controlled 256 bit value provided by the user. If we pass (1 &lt;&lt; 128) in the <code>msg.value</code>, <code>T::Currency::transfer</code> will do nothing because it’s transferring a truncated zero, and we’ll finish the EVM execution smoothly. We won’t get any extra balance by transferring the zero, but what if the giant untruncated <code>msg.value</code> is accepted by some contract that does give us credit? We could achieve the impossible and attack WETH to make it depeg!</p><p>The WETH contract allows users to deposit native ETH that users specify through <code>msg.value</code>. It stores this value internally after transferring the appropriate amount of tokens. Normally if you don’t have enough balance for the transfer, the transaction will be rejected or reverted. However, since we have bypassed the transfer validation by truncating to 0, the contract is willing to add our gigantic credit to our address in its internal balance mappings. Suddenly we have an astronomical balance in the contract and can drain all the deposited native tokens from the wrapped token contract!</p><p>To clarify, it’s not the WETH token itself on Ethereum that is vulnerable (but the title made you click, didn&apos;t it!), but the analogous wrapped native tokens of the polkadot parachains powered by the frontier EVM, such as WASTR in Astar, WGLMR in Moonbeam, and WMOVR in Moonriver, which are implemented using the standard WETH contract but on their respective parachains!</p><p>WETH contracts are not the only vulnerable targets. The Uniswap-like DEX trading pair contract accepts direct swapping from native ETH to ERC20 tokens. It trusts the <code>msg.value</code> too. Compound-like lending protocols usually provide a dedicated native token vault, handling both the deposit and withdrawal of native tokens. DEXes and lending protocols are the fundamental infrastructure of the DeFi world, any insolvency would be contagious. As I mentioned, any critical vulnerability that could depeg WETH is actually the nightmare of the whole ecosystem.</p><p>The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://pwning.mirror.xyz/okyEG4lahAuR81IMabYL5aUdvAsZ8cRCbYBXh8RHFuE">previous bug</a> had a similar effect, but required a tricky exploit. This bug is trivial but more destructive.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/03763fdd27029cb4356a6c801d16326a4fb8f97e2cb943a29cd8598d065ac5de.png" alt="the exploit" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">the exploit</figcaption></figure><p>The impact of the bug is complex. The direct exploit could drain all the wrapped token contracts. In addition to taking over the balance of the wrapped token, you can purchase other tokens from DEX by spending the rubber check from the wrapped token. Worse, a more sophisticated exploit could leverage the lending protocol to borrow all the other valuable tokens against the fake deposit.</p><p>At the time I reported the bug, the major victims were:</p><ul><li><p><strong><em>WMOVR</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonriver.moonscan.io/address/0x98878b06940ae243284ca214f92bb71a2b032b8a">https://moonriver.moonscan.io/address/0x98878b06940ae243284ca214f92bb71a2b032b8a</a> 560,369.286709772080185324 MOVR $6,511,491.11 (@ $11.62/MOVR)</p></li><li><p><strong><em>WMOVR</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonriver.moonscan.io/address/0xf50225a84382c74cbdea10b0c176f71fc3de0c4d">https://moonriver.moonscan.io/address/0xf50225a84382c74cbdea10b0c176f71fc3de0c4d</a> 39,495.093378689025337841 MOVR $458,932.99 (@ $11.62/MOVR)</p></li><li><p><strong><em>MGLMR</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonbeam.moonscan.io/address/0xacc15dc74880c9944775448304b263d191c6077f">https://moonbeam.moonscan.io/address/0xacc15dc74880c9944775448304b263d191c6077f</a> 22,509,169.750566904824477505 GLMR $15,462,674.16 (@ $0.69/GLMR)</p></li><li><p><strong><em>Wrapped Astar</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blockscout.com/astar/address/0xAeaaf0e2c81Af264101B9129C00F4440cCF0F720">https://blockscout.com/astar/address/0xAeaaf0e2c81Af264101B9129C00F4440cCF0F720</a> 233,903,992.470478147048553875 ASTR ($12,110,613 USD)</p></li><li><p><strong><em>WASTR</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blockscout.com/astar/address/0x19574c3c8FaFc875051b665Ec131b7E60773d2C9">https://blockscout.com/astar/address/0x19574c3c8FaFc875051b665Ec131b7E60773d2C9</a> 98,294,128.445114886025015582 ASTR ($5,080,234 USD)</p></li><li><p><strong><em>Wrapped Shiden</em></strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blockscout.com/shiden/address/0x0f933Dc137D21cA519ae4C7E93f87a4C8EF365Ef">https://blockscout.com/shiden/address/0x0f933Dc137D21cA519ae4C7E93f87a4C8EF365Ef</a> 9,348,196.210407926441765242 SDN ($3,310,196)</p></li></ul><p>The direct loss from wrapped token contracts could be more than <strong>$44M</strong>.</p><p>In lending pools the assets under risk is even larger:</p><ul><li><p><strong><em>Moonwell Apollo</em></strong> Total Supply $89,023,722 Total Borrow $41,595,374.52</p></li><li><p><strong><em>Moonwell Artemis</em></strong> Total Supply $179,023,716.01 Total Borrow $94,486,490.85</p></li><li><p><strong><em>Starlay Finance</em></strong> Total Deposited $37,163,238.35 Total Borrowed $18,769,822.51</p></li></ul><p>The remaining borrowable assets would be somewhere around <strong>$150M</strong>.</p><p>The vulnerability disclosure was troublesome as well. This bug affected at least two parachains: Moonbeam network and Astar network. I had to report to them simultaneously otherwise one team with earlier knowledge of the bug could conceivably launch an attack on the other one (I didn’t know if they were competitors). Furthermore, I noticed Acala network also shipped the same code, but they didn’t have as rich an EVM-based ecosystem as the other two, and the bug had no explicit impact on their system as a result, so I decided to postpone the bug disclosure to them.</p><p>All the three projects have their bug bounty program listed on Immunefi: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://web.archive.org/web/20220521163014/https://immunefi.com/bounty/moonbeamnetwork/">Moonbeam network</a>, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://web.archive.org/web/20220625225821/https://immunefi.com/bounty/astarnetwork/">Astar network</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://web.archive.org/web/20220625224811/https://immunefi.com/bounty/acala/">Acala</a>. Each project has a maximum bug bounty of <strong>$1M</strong> 😮. I was worried that the triage process on Immunefi might be delayed, so I tried to contact the first two teams as soon as I finished my <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/drives/b7ecc2e5-bbe6-4ac3-91a2-c4d5a6bb2fff?name=FRONTIER">POC and reports</a>. Thanks to the help from the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonwell.fi/">Moonwell</a> team, they set up a telegram channel between me and Moonbeam, who later invited the Astar and Polkadot guys to the group. All the bugs were quickly <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/paritytech/frontier/pull/753">patched</a>. A <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/paritytech/frontier/security/advisories/GHSA-hc8w-mx86-9fcj">security advisory</a> (CVE-2022-31111) was published later. This has been recorded on Moonbeam’s <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonbeam.network/blog/security-patch-for-integer-truncation-bug/">blog</a>.</p><p>Another interesting fact about the bug: a few hours after my report, the Moonbeam team identified a suspicious <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonriver.moonscan.io/tx/0xbb8913dfb35b70caa42da03fb874dc42768700c15b858d9fb30a2d672a497262">transaction</a> that triggered the vulnerability. You can see the transfer of 340,282,366 (T) MOVR! I believe the bug is dead now, but the corpse is living on the blockchain permanently.</p><p>The vulnerable substrate <code>frontier</code> is built by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.parity.io/">paritytech</a>, the team behind <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://polkadot.network/">Polkadot</a>. The Moonbeam team maintains its own fork at <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/PureStake/frontier">https://github.com/PureStake/frontier</a>. The Astar team forks from Moonbeam’s repo to <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/AstarNetwork/frontier">https://github.com/AstarNetwork/frontier</a>. All of them agreed to offer a bug bounty, but they decided to split a $1M bounty after months of negotiation🤣. To my surprise, Acala offered a huge bounty (compared to their negligible potential loss), which was also counted in the split. The final payout is $1M:</p><ul><li><p><strong><em>Moonbeam</em></strong> $430k</p></li><li><p><strong><em>Astar</em></strong> $250k</p></li><li><p><strong><em>Polkadot</em></strong> $250k, in DOT</p></li><li><p><strong><em>Acala</em></strong> $70k, in DOT</p></li></ul><p>Whether the result is $2M or $1M, since the bounty pays out in tokens living on the Ethereum blockchain, I guess I&apos;m pretty lucky that WETH wasn&apos;t vulnerable to this bug after all!</p>]]></content:encoded>
            <author>pwning-2@newsletter.paragraph.com (PWNING)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/3fabaff0e23fc56d83dbc6379a8febc98df477989312bb84c15fba7df14d8b4b.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[The Defrauded Fraud Proof of A Bitcoin Bridge]]></title>
            <link>https://paragraph.com/@pwning-2/the-defrauded-fraud-proof-of-a-bitcoin-bridge</link>
            <guid>dkNjiM5M8Why2Z9uBz6W</guid>
            <pubDate>Mon, 01 Aug 2022 12:32:42 GMT</pubDate>
            <description><![CDATA[Hanging out in the Immunefi discord leads me to new wonderlands! Last month I was notified of a new bounty program from Interlay, who claimed the maximal bounty payout could be $1M. Although the mainnet of its BTC bridge was not launched, they promised a minimum reward of $100k for critical bug reports. This journey took me out of the safety of the moonlight and into the uncertain darkness of collateralization. I dug into new concepts to bring familiarity to unfamiliar code. I quickly found a...]]></description>
            <content:encoded><![CDATA[<p>Hanging out in the Immunefi discord leads me to new wonderlands! Last month I was notified of a new bounty program from Interlay, who claimed the maximal bounty payout could be $1M. Although the mainnet of its BTC bridge was not launched, they promised a minimum reward of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://web.archive.org/web/20220630180653/https://immunefi.com/bounty/interlay/">$100k</a> for critical bug reports.</p><p>This journey took me out of the safety of the moonlight and into the uncertain darkness of collateralization. I dug into new concepts to bring familiarity to unfamiliar code. I quickly found a trivial bug, but I suspected that there was more. After some comprehensive research, I discovered a novel, exciting flaw. Both bugs have been confirmed as critical, leading to the decision to deactivate the vulnerable module.</p><p>To understand the hack, you, like I had to do, will have to start with the basics. So sit back, read on, and let&apos;s learn about collateral!</p><h2 id="h-the-interbtc-bridge-and-over-collateralization" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">the interBTC Bridge and Over-collateralization</h2><blockquote><p>The interBTC runtime allows the creation of interBTC, a fungible token that represents Bitcoin in the Polkadot ecosystem. Each interBTC is backed by Bitcoin 1:1 and allows redeeming of the equivalent amount of Bitcoins by relying on a collateralized third-party.</p></blockquote><p>Over-collateralization is a popular technique in DeFi protocols, enabling the minting of a synthesized asset from another base asset. Most Collateralized Debt Position (CDP) protocols are designed for minting stable coins from valuable but volatile assets. The most successful case of over-collateralization is the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://makerdao.com/">MakerDAO</a> protocol, which allows users to create debt in DAI by depositing ETH.</p><p>In the interBTC protocol, however, one is allowed to synthesize a mapping of a high value token (BTC) from its native tokens, like INTR and KINT. This feature is more like <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://synthetix.io/">Synthetix</a>, which allows minting any mapped assets by locking its native token SNX. The security of risky collateral usually means higher collateralization rate and lower capital efficiency. For SNX, the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.synthetix.io/litepaper/">Collateralization Ratio</a> (C-Ratio) is 400%. For interBTC, on their Kintsugi canary network, C-Ratio of KINT is 500%, C-Ratio of KSM (the native token of Kusama) is 150%.</p><p><strong>As pointed out by the interlay team, they use mainly the KSM/DOT assets (the ceiling of INTR/KINT is very low due to missing liquidity). They primarily target exogenously priced collateral assets rather than endogenous ones - more like Maker, but they allow a small portion of our native asset.</strong></p><p>The security properties are usually maintained by price oracles and arbitrageurs, but this may not work during market crashes. Luckily, the over-collateralization of interBTC is just the ​​last line of defenses, the system has guaranteed Bitcoin reserves as long as all the vaults are honest.</p><p>But how can we trust decentralized vaults that are controlled by anonymous entities? Now I will try to explain the innovation of interBTC’s fraud proof and slashing mechanisms.</p><h2 id="h-onchain-spv-and-fraud-proof" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Onchain SPV and Fraud Proof</h2><p>InterBTC is designed specifically for BTC, so it has to deal with the complexity of bitcoin transactions. It is clearly impossible to maintain all the transactions on chain, so the protocol works like a light wallet. Accordingly, the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://spec.interlay.io/security_performance/btcrelay-security.html">BTC-relay</a> module of the protocol implements the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://en.bitcoinwiki.org/wiki/Simplified_Payment_Verification">Simplified Payment Verification</a> (SPV). Instead of tracking all the unspent notes (utxo), only the minimal information of every bitcoin block header is stored on the chain. The relayers are in charge of the synchronization of block headers, providing the root of trust. The validation algorithm only needs to verify a given transaction</p><ol><li><p>has a valid merkle proof for its txid</p></li><li><p>the merkle root is found in the stored block headers</p></li><li><p>the corresponding block is mature enough</p></li></ol><p>Thus the system is able to check the validity of any interactions between users and vaults (specifically, transfers of a specific amount of BTC). Where would the users deposit to? To addresses prepared by the vaults in the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://spec.interlay.io/spec/vault-registry.html">registry</a> module. The vaults have to respond to reasonable requests from the user, and if no valid proof is supplied in a limited time, the locked collateral for that request will be slashed. All the required information is provided to the system, so it can confirm the honest behaviors with confidence.</p><p>What about malicious behaviors without corresponding user requests? The off-chain relayers monitor and check that vaults do not move BTC, unless expressly requested during <code>Redeem</code>, <code>Replace</code> or <code>Refund</code>. If a malicious vault moves BTC without authorization by the bridge, or reuses the authorization by committing the same <code>OP_RETURN</code> transaction, all of its collateral will be slashed. These two behaviors are reported by <code>report_vault_theft</code> and <code>report_vault_double_payment</code> extrinsics respectively.</p><p>Therein lie the bugs...</p><h2 id="h-bug-1-double-payment-force-liquidation" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Bug 1: Double Payment Force Liquidation</h2><p><code>report_vault_double_payment</code> is exposed as an extrinsic call method. It takes two raw txs and verifies that they share the same input and reference the same user requests.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2b88c1f56f8124ae1cfbd4f8df256f7ee798d9b209b3815db673194ca2cee10f.png" alt="report_vault_double_payment" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">report_vault_double_payment</figcaption></figure><p>The two txs are compared to ensure they are different. However, the check of <code>Vec&lt;u8&gt;</code> is incomplete.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/6230b539a3776040f7d7404f13ce0c5c61df543b7010658afef52e3aa9b0b5c7.png" alt="parse_transaction" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">parse_transaction</figcaption></figure><p><code>BytesParser</code> ignores trailing bytes of the raw transaction, so different <code>raw_txs.0</code> and <code>raw_txs.1</code> can be parsed into same <code>Transaction</code>, bypassing all the following checks in <code>report_vault_double_payment</code>.</p><p>All the vaults with at least one processed user request (Redeem, Replace or Refund), are vulnerable to this force liquidation. The attacker would steal 5% of the vault&apos;s collateral, leaving the whole system broken: all the collateral would be transferred to the liquidation account and all vaults would be banned.</p><p>The bug is pretty simple. In the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/file/5796e38f-2482-4471-8890-91b18401f96d/view">POC</a>, a fake tx is crafted by simply appending an extra byte to the original tx. My patch and testcase were later adopted in their <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/interlay/interbtc/commit/3ef1476649697d6f7bbf785e39882ad965bd2ba8">commit</a>. <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/file/45c245c8-8b31-4052-9572-f072a54e2c5d/view">Full Report</a></p><h2 id="h-bug-2-p2sh-address-forgery" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Bug 2: P2SH Address Forgery</h2><p>The bitcoin address itself is a pretty interesting topic. There are many variants of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://learnmeabitcoin.com/technical/address">address</a>: P2PK, P2PKH, P2MS, P2SH, P2WSH, P2WPKH… It’s super confusing! Why?</p><p>As you may (should!) already know, there is no such concept as an <em>account</em> in Bitcoin: all the balances are maintained by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://learnmeabitcoin.com/technical/utxo">utxos</a>. Every utxo has a <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://learnmeabitcoin.com/technical/scriptPubKey">ScriptPubkey</a>, which can only be unlocked by the corresponding ScriptSig. The different types of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://learnmeabitcoin.com/technical/script">common ScriptPubkey</a> are encoded in addresses of various forms. Notice that they are actually tiny scripts that support limited operations in the special stack-based virtual machine inside Bitcoin.</p><p>The interBTC system currently supports 4 types of addresses: P2PKH, P2SH, P2WPKHv0 and P2WSHv0. The vaults can freely register any type of address. One of these types is particularly interesting, P2SH – <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://learnmeabitcoin.com/technical/p2sh">Pay To Script Hash</a>. This feature has a subtle quirk: any ScriptPubkey can be encoded in a vault address with just its hash, and the actual ScriptPubKey will only be provided by the corresponding ScriptSig (and verified against the stored hash). Subsequently, the rest of the ScriptSig (which is not checked against any hashes), just like the key to a lock, can be forged arbitrarily to match the mutable ScriptPubkey!</p><p>The malleability of ScriptSig is not a nightmare until it is used in a SPV system. Due to the reduced amount of information stored in SPV, there is no way to lookup the matching ScriptPubkey of a ScriptSig (unlike a full node, which can look it up in the chain). So the system has to extract the ScriptPubkey/address from the ScriptSig. The extraction of the address must be accurate, otherwise</p><ul><li><p>Attack 1: If the correct address is not recovered from the ScriptSig, the use of the uxto will not be considered as the action of the vault, thus the misbehavior will never be confirmed by <code>report_vault_theft</code>.</p></li><li><p>Attack 2: If the extracted address is misinterpreted as an address of another vault, the benign vault will be slashed by <code>report_vault_theft</code>.</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/5dfb37a58393917c121105c0abc326f6abe34eaea0c5de0a2ea94ae532fc435b.png" alt="extract_address_hash_scriptsig" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">extract_address_hash_scriptsig</figcaption></figure><p>Unfortunately, the address extraction algorithm is neither sound nor complete. For example, it only accepts a subset of valid addresses and detects the P2SH address by checking if the first opcode is <code>OP_0</code>. If the ScriptSig violates the hardcoded templates of P2SH and P2PKH, the correct address will not be recognized, leading to Attack 1. If the ScriptSig is carefully crafted by the attacker, any P2PKH or P2SH addresses can be counterfeited. That is Attack 2. It&apos;s worth noting that Attack 1 can be a side-effect of Attack 2.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f4f76115136fd620965eebb13ad68d34b47c971fc2e609c556c73d6739f6526a.png" alt="poc-2.py" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">poc-2.py</figcaption></figure><p>In the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/file/9cd69395-ad2f-48d6-89a5-66e97e94de4d/view">POC</a>, I use a P2SH address corresponding to a special redeem script and construct a transaction by spending from that P2SH address. The redeem script consumes 3 elements from stack: [fake sig, fake pubkey, real sig]. It has two <code>OP_NIP</code> opcodes that drop the first two elements of the input stack. The remaining <code>real sig</code> is verified with the hardcoded real pubkey. Because the first two elements, sig and pubkey, are pushed into stack just like other common P2PKH scriptsig, the extracted address from this scriptsig will be just like a normal P2PKH address from the fake pubkey (the fake sig is unused), thus leading to Attack 2. The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blockstream.info/testnet/tx/e0d2457036493db0787636a926b543f96dbfca157a6ca81d5fb97f2cc70e1e5b?expand">transaction</a> has been confirmed in the testnet. <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/file/14e8a1a0-1dcf-4921-88a4-041d8f4959d5/view">Full Report</a>.</p><p>Patching the design failure is tricky: introducing stricter validations means more chances of missing actual thefts. The interlay team handled the issue quickly and decided to deactivate the vulnerable theft reporting functions. However, my exploration didn’t stop here.</p><h2 id="h-bonus-segwit-address-confusion" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Bonus: Segwit Address Confusion</h2><p>The P2SH address is not the only type of address with a customized script. P2WSH, the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://en.bitcoin.it/wiki/Segwit">segwit</a> version of P2SH, works in a similar fashion, but the script is revealed inside of the witnesses instead of the ScriptSig. P2WPKH is another specially handled address type, validating the user public key embedded in witnesses. For both cases, there is a deterministic algorithm to infer the correct address from the witnesses. I failed to break the segwit style addresses at first, but eventually I found a weakness!</p><p>The extraction algorithm only cares about the last element of the witnesses, because it is either the public key for P2WPKH, or the ScriptPubkey for P2WSH.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c7fe7833e91f4ffade605dfdf49cd9cb30a468305e87ade7da10a82fa25a62f4.png" alt="extract_address_hash_witness" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">extract_address_hash_witness</figcaption></figure><p>So, how can an SPV system determine the exact type of the original address in the unified algorithm? Heuristics again! If the witness of P2WSH address looks like a valid public key:</p><ol><li><p>length in 33 bytes</p></li><li><p>first byte is ‘\x03’ or ‘\x04’</p></li></ol><p>then it is considered a valid P2WPKH address.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d2dd012798ceb64aaf51168c950c794d5985044f89198ec5b342d45ae3f8e501.png" alt="bonus.py" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">bonus.py</figcaption></figure><p>Some knowledge of the opcodes is required for building this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/file/ed8af0ee-1513-4c02-9266-1a41c72bf57a/view">tricky script</a>. The confirmed <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blockstream.info/testnet/tx/478830a64f4bb962d151c7248d03b1e76e8e99224b475f8dd3550c96f8cea09a?expand">transaction</a> is on the testnet.</p><h2 id="h-downgraded-security" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Downgraded Security?</h2><p>In the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://medium.com/interlay/kintsugi-released-urgent-security-patches-aebf969ee087">postmortem</a> of the interlay team, they have decided to remove the theft reporting functions. As we have discussed in the first section, the removal of fraud proof downgrades the security: it degenerates interBTC into a basic over-collateralization system, just like Synthetix. Will it be a problem? In theory, its economic security is <strong>unaffected</strong>.</p><p><strong>There is no guarantee that a vault still holds BTC, but the value at risk for the vault is still the same. So if a vault does not send BTC at the time of redemption it is still the same decision process: keep BTC or lose collateral at the time when the user redeems.</strong></p><p>However, the security achieved through sophisticated economic designs does not always work. While searching for more instances of failed fraud proof, I came across an unexpected protocol, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/harmony-one/onebtc">ONEBTC</a>, the “Trustless Bitcoin on Harmony”. They listed <code>interlay/BTC-Bridge</code> and <code>interlay/BTC-Bridge-Spec</code> in their references! Their code looks like an old version of interlay BTC bridge, with some random customizations (comment out some functions deliberately).</p><p>In <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/harmony-one/onebtc/blob/main/contract/bridge/contracts/OneBtc.sol">OneBTC.sol</a>, they have implemented <code>reportVaultTheft</code> and <code>reportVaultDoublePayment</code>! But these functions are restricted by requiring <code>relay.isApprovedStakedRelayer(msg.sender)</code>, and they don’t really parse the transactions – they just slash anybody unconditionally!</p><p>I have not verified if they had ever used the fraud proof functions, but even if that happened, it would not be in a <code>trustless</code> style as they claimed (and users expected). It turned out that the “optimistic” and semi-trustless bridge worked pretty well, the decentralized nature of vaults were immune to the compromised private key! The ONEBTC bridge was the only survivor of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://medium.com/harmony-one/harmonys-horizon-bridge-hack-1e8d283b6d66">the epic nine figure hack</a>.😓</p><p>Funds SAFU? Maybe not... The fluctuation of its collateral, Harmony (ONE), caused a huge risk of under-collateration. The emergency (still ongoing!) freeze of the bridge reinforced the crisis. The users might not be able to cash out, but the vault operators can leave this dangerous game freely, because the raw Bitcoin is unstoppable!</p><h2 id="h-closing-thoughts" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Closing Thoughts</h2><p>Given the potential for deceit that we find again and again in not just crypto, but almost every inter-human transaction, did we truly expect it to hold secure? Humans have been forging coins, cash, and checks for centuries. Is it really unexpected that, given the chance, we would forge <em>scripts</em>?</p><p>What keeps the darkness at bay? I hope that, in a small part, I&apos;ve helped keep it at bay with this report. Perhaps there was a potential future with a headline of an interBTC hack that now won&apos;t happen. Perhaps not. But what there is, is you. I am but one hacker, just months into my crypto journey. You can come walk it with me: what took me months can take you weeks, and you, too, can keep crypto safe.</p>]]></content:encoded>
            <author>pwning-2@newsletter.paragraph.com (PWNING)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/e89a447a79776d7f212686e8d5dbb5195812409c875f25452cf35b091229760a.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[How to Steal $100M from Flawless Smart Contracts]]></title>
            <link>https://paragraph.com/@pwning-2/how-to-steal-100m-from-flawless-smart-contracts</link>
            <guid>u32gF1nxI7khh0AJhKRT</guid>
            <pubDate>Wed, 29 Jun 2022 00:07:41 GMT</pubDate>
            <description><![CDATA[My blockchains adventure continues! This time I protected Moonbeam network by disclosing a critical design flaw, safeguarding more than $100M assets at risk in various DeFi projects. I was awarded the maximum reward amount of their bug bounty program on Immunefi, $1M, and $50k bonus from Moonwell (I guess that’s also one of the top 10 highest bug bounties?)Delegatecall and Native ContractsAfter reporting the bug in Aurora engine, I started to think about the other potential misuses of delegat...]]></description>
            <content:encoded><![CDATA[<p>My blockchains adventure continues! This time I protected Moonbeam network by disclosing a critical design flaw, safeguarding more than $100M assets at risk in various DeFi projects. I was awarded the maximum reward amount of their bug bounty program on <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://immunefi.com/bounty/moonbeamnetwork/">Immunefi</a>, $1M, and $50k bonus from <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://immunefi.com/bounty/moonwell/">Moonwell</a> (I guess that’s also one of the top 10 highest bug bounties?)</p><h1 id="h-delegatecall-and-native-contracts" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Delegatecall and Native Contracts</h1><p>After reporting <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/pwning.eth/CB4XUkbJVwPo7CaRwRmCApaP2DMjPQccW-NOcCwQlAs">the bug in Aurora engine</a>, I started to think about the other potential misuses of delegate calls of native contracts. The original purpose of the <code>delegatecall</code> was to provide a mechanism through which one smart contract could share and reuse the code of another one’s to avoid the overhead of duplicated code storage. Native contracts are usually prebuilt contracts that implement special functions as extensions of the original EVM.</p><p>Now, the tricky part: if you <code>delegatecall</code> to a native contract, you may be able to execute some unexpected functions, even privileged ones! However, the developers of those native contracts might not realize that the actual user of the functions could be someone else. In the Aurora bug&apos;s case, the native contract just assumes the caller will always be a magical address, so the hardcoded log emitter leads to the malicious withdrawal vulnerability.</p><p>What other assumptions could be wrong? When you do a <code>delegatecall</code>, the calling context is inherited from the previous one, including the <code>msg.sender</code> and <code>msg.value</code>. From the view of a native contract, the contract that invokes <code>delegatecall</code> is transparent: its caller will be considered the real user instead. So if a malicious contract is invoked, it can impersonate its caller to operate on the native contracts!</p><h1 id="h-shadow-in-the-moonbeam" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Shadow in the Moonbeam</h1><p>Moonbeam and Moonriver are both EVM-compatible platforms. There are some precompiled contracts in moonbeam runtime which are shared between Moonbeam and Moonriver.</p><p>The Balance ERC-20 precompile provides an ERC-20 interface for handling the native tokens (<code>MOVR</code> &amp; <code>GLMR</code>) of balance. The implementation <code>Erc20BalancesPrecompile</code> is in <code>moonbeam/precompiles/balances-erc20/src/lib.rs</code>.</p><p>The designer did not take the usage of `delegatecall` in EVM into consideration. A malicious contract can pass its <code>msg.sender</code> to the precompile contract to impersonate its caller. In this scenario, there is no way for the precompile contract to figure out the actual caller. The attacker can either increase the allowance from the victim or transfer the available balance immediately.</p><p>There are similar issues in the Asset ERC-20 precompile, which provides an ERC-20 native implementation of interoperable tokens (<code>xcKSM</code>, <code>xcDOT</code>, ...). The implementation <code>Erc20AssetsPrecompileSet</code> is in <code>moonbeam/precompiles/assets-erc20/src/lib.rs</code>.</p><p>However, the designer <em>did</em> consider the usage of <code>delegatecall</code> in EVM for this case. The <code>ERC20Instance</code> contract in the tests has implemented <code>approve_delegate()</code>, <code>transfer_delegate()</code> and <code>transferFrom_delegate()</code>, with test cases ensuring their validity. Unfortunately (or, for us, fortunately!), it turns out that the design logic can not work properly, so they have removed the relevant code in their <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/PureStake/moonbeam/pull/1551/files#diff-1404c7c10c00572e96e647084d96576f592a2c18e70f53cdcfec2daa98adb60cR119">patch</a>.</p><p>Here is a simple exploit that can be reused in both cases: the <code>asset</code> address of native token is <code>0x0000000000000000000000000000000000000802</code> and the <code>asset</code> address of a local token could be <code>0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080</code>.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/757415397027eb6bb4190a262927b4f34bf28f552dcdbeb05c75da41a43f9362.png" alt="Exploit.sol" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Exploit.sol</figcaption></figure><h1 id="h-perfect-contracts-or-perfect-victims" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Perfect Contracts, or Perfect Victims?</h1><p>What can we do with the design flaw? The basic idea is to ask someone to trigger your malicious contract, e.g., calling the <code>trap()</code> in the POC contract.</p><p>How can we persuade users to invoke some mysterious contracts? By Airdrop! The hackers behind the <code>UNIH</code> token have demonstrated the crypto-native solution of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.runebase.org/news/beware-of-unih-airdrop/">phishing</a>! Any user who wants to sell an airdropped token in uniswap has to call the malicious token contract to approve the DEX to spend their balance. Due to the vulnerable design of RUNE tokens, where only the <code>tx.origin</code> instead of <code>msg.sender</code> is checked for approval, all the RUNE tokens could be stolen by a trojan contract.</p><p>The phishing idea is creative, but it strongly limits the potential damage of the vulnerability. We want to find a better victim that is</p><ol><li><p>willing to call your contract</p></li><li><p>not as smart as users</p></li><li><p>rich!</p></li></ol><p>Who are the best friends of poor hackers? The flash loan providers! They hold a lot of money and call your contract callbacks as you wish! In the flash loan callback, they are forced to approve your future transfer of their asset tokens, even if they are flawless contracts!</p><p>Some DEX pairs support callbacks to arbitrary contracts, such as SolarBeam on MoonRiver and StellaSwap on Moonbeam. The stable swap pair between <code>xcKSM</code> and <code>stKSM</code> is also vulnerable due to the support of flash loans. If one token can be drained from the trading pair, then the other token can be moved out in one single swap, all the liquidity will be cleared.</p><p>Now the perfect written contracts become perfect victims. By the time I reported, the richest vulnerable contracts were:</p><ol><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonriver.moonscan.io/address/0xea3d1e9e69addfa1ee5bbb89778decd862f1f7c5">0xea3d1e9e69addfa1ee5bbb89778decd862f1f7c5</a> on Moonriver, SolarBeam LP Token, $7.5M</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonbeam.moonscan.io/address/0xa927e1e1e044ca1d9fe1854585003477331fe2af">0xa927e1e1e044ca1d9fe1854585003477331fe2af</a> on Moonbeam, Stella LP Token, $2.7M</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://moonriver.moonscan.io/address/0x77d4b212770a7ca26ee70b1e0f27fc36da191c53">0x77d4b212770a7ca26ee70b1e0f27fc36da191c53</a> on Moonriver, xcKSM &amp; stKSM pair, $2.4M</p></li></ol><p>These tokens are worth about $12.6M, even a 10% potential loss is already more than $1M, the maximal bounty prize that Moonbeam offers. But real hackers won’t be stopped by trivial achievements, will there be any crazier victims?</p><h1 id="h-the-glimmer" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">the Glimmer</h1><p>The native tokens <code>MOVR</code> (on Moonriver) and <code>GLMR</code> (on Moonbeam) are equivalent to <code>ETH</code> on Ethereum. To be used in DeFi protocols, they have to be wrapped in ERC-20 compatible token contracts, just like <code>WETH</code>.</p><p>The Balance ERC-20 precompile provides the native wrapper of the native tokens. None of any deployed protocols ever use it because the official wrapped tokens <code>WMOVR</code> and <code>WGLMR</code> are more widely adopted. By leveraging the vulnerability of the Balance ERC-20 precompile, we are able to steal the native token balance from any userif it invokes the malicious contract. Unlike the Asset ERC-20 precompile tokens, e.g., <code>xcKSM</code> and <code>xcDOT</code>, which are directly used by DEXes, <code>MOVR</code> and <code>GLMR</code> balances are rarely used by smart contracts.</p><p>Most contracts with non-zero balances are multisig wallets, which are not so different from the externally owned accounts. The only exception, our glimmer of hope, is the <code>MGlimmer</code> contract of the Moonwell project.</p><p>The Moonwell project is the dominant DeFi protocol on Moonriver. It has nearly $200M in supply and $100M available for borrowing (at the time I reported). <code>MGlimmer</code>, or <code>Moonwell: mMOVR Token</code> is the specific contract that handles the lending and borrowing against <code>MOVR</code>, and it has the native <code>MOVR</code> in its balance.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b98747a5deb8efcc6a9d32f09cb00a3763300aa7077d0f54d2b2c5cafe689570.png" alt="MGlimmer.sol" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">MGlimmer.sol</figcaption></figure><p>The cool thing is that when it transfers the balance to the user, it will call the destination as a contract! Here is a simple exploit that gains the approval of spending all the balance of <code>MGlimmer</code>.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e6737227971aa4401d48120588d11b18e05e84d28920afafe9f3ecd43bfd4cba.png" alt="GlimmerExploit.sol" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">GlimmerExploit.sol</figcaption></figure><p>The balance stored in the vulnerable contract is not too much (a few thousand of <code>MOVR</code> now). Still, any amount you deposit into that contract will be considered your collateral in this lending protocol. The exploit can be further weaponized by repeating the deposit -&gt; borrow -&gt; transfer all back -&gt; leave bad debt procedure. All borrowable assets can be drained!</p><p>It could absolutely be in the top 10 heists of DeFi history if any hacker took all the $100M borrowable assets plus $12M vulnerable tokens in DEX pairs! Another amazing fact about these vulnerabilities is that actual attacks could be super stealthy by only keeping the unauthorized privilege instead of stealing immediately. Since the contracts themselves are flawless, it’s almost impossible for the developers of those DeFi projects to figure out what is going wrong!</p><h1 id="h-responsible-disclosure" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Responsible Disclosure</h1><p>Everybody is struggling in the bear market. I don’t want to hurt anyone, I want to help, especially when they are such hard working teams. So I tried my best to help the project teams understand the root causes and speed up the patching process.</p><p>The situation here is extremely complex at first. The flaw is in the deep core of the blockchain system, but the victims are the DeFi protocols built on top of it. Some protocols may have emergency exits to pause and upgrade their contracts, while others are just immutable.</p><p>The ultimate patch has to be made by the Moonbeam team, but the biggest victim, Moonwell, could have mitigations for this vulnerability before the actions of the Moonbeam. I noticed that both Moonbeam and Moonwell had launched their bounty program on Immunefi, so I discussed with the Immunefi team the potential special case (without disclosing the specific name of the projects). After realizing that other projects, like the uniswap style DEXes, can not really do anything useful, I decided not to report to them to minimize the risk of leaking the critical information. Since only the Asset ERC-20 issue might be a problem for the Moonwell team, I have to split the report for Moonbeam into two parts, only the necessary information and the exclusive GlimmerExploit POC are submitted to them.</p><p>I took special care of the Moonbeam team, even if they might not be aware of that. I spent extra hours learning their code base and writing two <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/drives/fd36175d-fd51-4a02-8c09-b012dd2f044c?name=MOONBEAM">complete test cases</a> (600+LOC) just in case they needed more explanation of the root cause. I asked the common timezone of the PureStake team in their discord to make sure I submit the report once the first engineer comes to work. Luckily, it worked out: they started handling this issue on Friday and finished the patch before the weekend without any inquiries!</p><p>Is this the last unexpected flaw hiding near the core design of blockchain-based smart contracts? Certainly not! For every <code>delegatecall</code>, there&apos;s another, even wilder issue hiding in the darkness. There are always other, more exotic issues waiting for me!. Stay with me on my journey as I find these bugs, push them into the light, and make the blockchain safer for everyone!</p>]]></content:encoded>
            <author>pwning-2@newsletter.paragraph.com (PWNING)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/b131db2988ba7018e381ef822e96ca1bc60096cc8d8334381bc367ca1b173f73.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[How did I Save 70000 ETH and Win 6 Million Bug Bounty]]></title>
            <link>https://paragraph.com/@pwning-2/how-did-i-save-70000-eth-and-win-6-million-bug-bounty</link>
            <guid>6J8E8JCc0CNstLMNBptV</guid>
            <pubDate>Tue, 14 Jun 2022 16:56:11 GMT</pubDate>
            <description><![CDATA[Hi! I am pwning.eth, a wanderer in the hacking space who has recently jumped into the wonderland of crypto. A few months ago, I reported a critical bug in the Aurora Engine, a layer 2 EVM solution built on the NEAR protocol. At least 70000 ETH were at risk of being stolen, until I found the tricky vulnerability and helped the Aurora team fix it. It would be in the top 5 heists in the defi history, if the 200 million tokens were taken over by a blackhat hacker. In the end, I won a bug bounty o...]]></description>
            <content:encoded><![CDATA[<p>Hi! I am <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/PwningEth">pwning.eth</a>, a wanderer in the hacking space who has recently jumped into the wonderland of crypto. A few months ago, I reported a critical bug in the Aurora Engine, a layer 2 EVM solution built on the NEAR protocol. At least 70000 ETH were at risk of being stolen, until I found the tricky vulnerability and helped the Aurora team fix it. It would be in the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://rekt.news/leaderboard/">top 5</a> heists in the defi history, if the 200 million tokens were taken over by a blackhat hacker. In the end, I won a bug bounty of 6 million, which was the second highest bounty in history.</p><p>I am an experienced whitehat hacker from the web2 world. I have been watching the hacking drama in the crypto world for a while, and there is so much randomness! I am not too surprised at the astronomical profits of defi hackers, because the criminals in the real world also make an insane amount of money. However, I was really shocked by the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.saurik.com/optimism.html">story</a> of saurik, a famous hacker in the jailbreak community. The size of his bug bounty is unheard of in the traditional security world, and so I can’t wait to start my own treasure hunt in web3.</p><p>I started by checking the bounty list on Immunefi. The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://immunefi.com/bounty/aurora/">Aurora bounty program</a>, listed on the very top of the website due to its huge bounty offer, caught my eye. It was a novel project built by a group of talented engineers, which suggested that it might be complex enough to be immune to common defi hackers and mysterious enough for me to learn something magical. Thanks to my experiences in hacking modern complex systems, I was able to start my research on the new blockchains quickly. I had reviewed the Aurora bridge, which was a solid project. Then I moved on to the Aurora engine and discovered the unicorn bug in a few hours. Unlike ordinary defi vulnerabilities, I didn&apos;t think this bug could be identified by random people as fast or lucky as me, so I took my time verifying and reproducing the bug in case it was a false alarm. It took me a few days to learn, build, learn, test and finally finish the report.</p><p>I tried pinging the Aurora team in discord, sending messages to the official bounty email and submitting the issue through Immunefi. They confirmed and patched the vulnerability quickly, and have since recounted the general <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://aurora.dev/blog/aurora-mitigates-its-inflation-vulnerability">story</a>. Their rewards for smart contract critical vulnerabilities are calculated as 10% of potential economic damage of their exploitation, up to a value of $6,000,000 USD. In this case, the potential damage could have been higher than ten times this maximum reward. Therefore I was eligible to receive the maximum possible amount, the total value of $6,000,000 USD, in the form of locked AURORA tokens. It’s a pretty smart and lucky move to be listed on Immunefi :)</p><p>The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://medium.com/immunefi/aurora-infinite-spend-bugfix-review-6m-payout-e635d24273d">technical details</a> have been explained by Immunefi. Here is my short summary:</p><ol><li><p>The Aurora engine implements token bridging in prebuilt contracts at hardcoded addresses. They are the magical bridges connecting Ethereum, NEAR and Aurora.</p></li><li><p>The vulnerable contract always emits a fixed address in bridging events, assuming the <code>msg.value</code> will be collected by itself. However, if the contract is invoked by <code>delegatecall()</code>, the <code>msg.value</code> will never be sent to the contract but the log will be emitted as usual.</p></li><li><p>By repeating the malicious withdrawal then redeposit process, the attacker can double their balance exponentially. The infinity inflation of ETH could have destroyed the whole ecosystem of Aurora: all 71k ETH in the <code>aurora</code> account could have been drained, and other valuable tokens could have been purchased by free ETH. (There were billions of TVL in the Aurora bridge.)</p></li></ol><p>If you are hardcore enough, you may find the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://app.ardrive.io/#/drives/7ba902d8-d26a-4dad-99b8-807eaaf8d925?name=AURORA">original report and scripts</a> interesting, enjoy!</p>]]></content:encoded>
            <author>pwning-2@newsletter.paragraph.com (PWNING)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/fd1865785f970b74b96500551649cbeca8ffdda5419eb3a466542a8b76a5f0c4.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[The Genesis Block]]></title>
            <link>https://paragraph.com/@pwning-2/the-genesis-block</link>
            <guid>j05s80rZu6qyanyuxgTr</guid>
            <pubDate>Mon, 13 Jun 2022 16:20:08 GMT</pubDate>
            <description><![CDATA[Hi! I am pwning.eth, follow me @PwningEth and start our great journey in web3!]]></description>
            <content:encoded><![CDATA[<p>Hi! I am <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0x4141414141f548abbee730b8b33a1eff7ee5bbad">pwning.eth</a>, follow me <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/PwningEth">@PwningEth</a> and start our great journey in web3!</p>]]></content:encoded>
            <author>pwning-2@newsletter.paragraph.com (PWNING)</author>
        </item>
    </channel>
</rss>