What are the challenges of a 2 way peg BTC on Stacks?

Hello! I’m thinking about a trustless 2 way peg BTC mechanism in Stacks because as far as I know it’s theoretically possible.

To peg in you burn BTC using OP_RETURN. The peg out could work like PoX. You could send your, let’s say, xBTC to a contract where it’s gradually destroyed as miners send BTC to your address, just like miners send BTC to stackers right now.

The main tradeoff seems to be that the peg out is limited in time by the Stacks block reward. For instance, if the block reward equals to 0,1 BTC and you want to peg out 1 BTC you have to wait 10 blocks (or more). Other users have to wait too, currently the BTC is only sent to you.

This mechanism has to be encoded in a consensus rule because it’s about mining. If there are peg outs it means less BTC is transferred to stackers or burned. That’s why I think it shouldn’t be costless, because you are consuming BTC that otherwise would be destined to PoX or PoB. It could be implemented like an auction with a minimum fee.

Now that you have the trustless 2 way peg mechanism you don’t really need to use it. It’s more efficient to simply do atomic swaps.

I’m sure I’m missing a lot. What are the challenges of building such a mechanism?

1 Like

ping @jude @psq @friedger ?

2 Likes

I wrote a tweetstorm about using PoX as the underlying mechanism that implements a 2wp a few weeks ago: https://twitter.com/JudeCNelson/status/1380688464744701954. It’s similar to what I think you’re proposing.

Fundamentally, what you’d need to do is make it so a reward-slot holder can sell you a reward slot that they’d lock up for you with your BTC address in a future PoX reward cycle, so you’d receive the BTC. In exchange, you’d surrender the equivalent amount of xBTC, and you’d probably pay some kind of service fee. Then, once the PoX protocol pays you your BTC, the reward-slot holder would be able to submit the block-commit transaction to an escrow contract holding your xBTC and service fee as proof-of-payment, so they can claim the service fee (the xBTC would be destroyed then).

You don’t need to make any consensus changes to achieve the above – you could do this today. The amount of BTC transferred would be the same. However, you’d have to convince someone to let you use their BTC reward slot – such as by paying them a service fee. Other mechanisms and organizing principles are possible – for example, a group of STX holders who regularly transact in xBTC might decide to form their own private Stacking pool in which they’d be able to convert their xBTC back into BTC.

2 Likes

Thanks Jude! As far as I know the long term goal of Stacks is to be a PoB system, so this 2wp mechanism would not be possible.

But I think this is huge. We can see an impressive amount of BTC going to Ethereum (according to coinmarketcap there are more than 180,000 wBTC), Stacks could do the same but trustlessly! So my idea was more like having this mechanism even for PoB. BTC would be burned by default (PoB) but if a user pays to peg out miners have to send BTC to him (it’s a consensus rule).

This would also allow people to earn xBTC by holding STX (similar to stacking). For instance, if you want to do a peg in you receive the same quantity of xBTC minus a fee that goes to stackers. If you want to do a peg out you pay another fee. The more xBTC the more BTC burned (peg in) and the more xBTC to stackers. This fee makes sense because stackers give value to STX, and as long as STX has value (giving value to the block reward), peg out is possible.

I think the incentives of such a system are fine for both BTC holders and STX holders. You have PoB, 2wp and pseudo-PoX (stackers earn xBTC). Appchains on top of Stacks could also use xBTC (for PoX or PoB).

Maybe I’m missing something, is this possible?

The rationale for this is that, as a closed-system where miners’ only profitability comes from STX, PoX is not incentive-compatible. Miners’ highest payout comes from stacking their STX in order to discount-mine, since if they stack enough STX, they’ll reliably get their BTC back (and moreover, miners would pay the highest price for STX on the open market, because the upside is nearly-free STX forever). By contrast, PoB mining is incentive-compatible, because the miners’ highest payout comes from selling their STX.

In practice, mining happens in the context of a whole host of different incentives which can’t be easily modeled (or even determined). One change we’re considering in 2.1 is making it so that a minority of STX holders can vote to disable PoX on a reward-cycle basis, and in doing so, prevent discount-mining. It needs more consideration though.

It’s not clear to me that you even need a consensus change, even if the system went full PoB. If you wanted to peg-out xBTC, you don’t need to tie it to mining, because you can just sell the xBTC back for BTC via a cross-chain atomic swap on Bitcoin. If Alice wanted to sell xBTC to BTC, she would put her xBTC and Bitcoin address into the peg-out contract in escrow, as well as a STX fee to be paid to whomever can post proof-of-payment for her xBTC on the BTC chain. If Bob wanted to buy Alice’s xBTC, he would pay the requisite amount of BTC to Alice’s Bitcoin address, and once the BTC transaction confirms, he’d post it to the peg-out contract to claim Alice’s STX fee and destroy the xBTC paid. The contract has access to the Bitcoin block header hashes, so it would be able to automatically verify that Bob’s transaction was indeed mined on the Bitcoin chain. Because the xBTC are fungible, he doesn’t even need to buy all of Alice’s xBTC – he can buy only what he wants, and the escrow contract would destroy only the xBTC that was redeemed.

EDIT: One thing that’s really unclear to me is how the xBTC are valued. If you mint them by burning BTC, then it decreases the amount of liquid BTC that can be used to redeem the xBTC later. Over time, this should cause the xBTC to depreciate. You’d have to find some way to avoid this.

I think I don’t follow you. Why would anyone send BTC to only receive an STX fee (the xBTC is destroyed)? No one is going to pay BTC unless the STX fee is of higher value, in that case the xBTC user is not pegging out, he is literally buying BTC with STX!

You need someone to pay the peg out, in my idea the miners would pay it because they receive the STX block reward doing so. So it involves mining, in other words, the consensus mechanism.

Also you cannot do it with PoX right now because no one is going to stack for you if you pay less than the PoX reward. If you pay stackers more than the PoX reward, and you receive the PoX reward as peg out, then you are buying the BTC, not doing a peg out!

That’s why you need to change the consensus algorithm to trustlessly peg out. But the peg out is limited in time by the STX block reward value (miners pay BTC up to the value of the STX block reward). If the STX price falls a lot against BTC, xBTC could depreciate against BTC (in market value) because using the peg out mechanism takes a lot of time. Ideally xBTC users pay fees (I would say periodically) to STX holders so that if a lot of xBTC is created, STX goes up in value (stackers earn more) and the bottleneck does not become a problem (the block reward is higher so more xBTC can be pegged out). xBTC users are using Stacks to get the most out of BTC (trustless DeFi for BTC) and it’s not a big deal paying a little fee periodically. The more xBTC -> the more value STX has -> the more xBTC can be pegged out during the same time.

Stacks could work with PoB, when the peg out contract is fulfilled with xBTC miners have to send BTC to the peg out address as part of the consensus protocol. STX holders earn through xBTC user fees. The mining mechanism assures you the peg out, but you can do atomic swaps. I would appreciate your opinion about it.

You need to think about this problem a lot more than you than you appear to have done.

First, you can’t force miners to peg-out simply by requiring that all mined peg-out transactions be fulfilled with BTC payments in order for a block to be valid. All this will do is cause miners to simply ignore peg-out transactions in the mempool, unless the associated transaction fee is so high that it effectively constitutes a BTC purchase. Miners choose what Stacks transactions get mined in Stacks blocks, and can determine what they will do before choosing to mine them. If there are no peg-out transactions mined (not pending, but mined), then miners don’t need to peg-out at all. Why do you expect that miners will pick up a peg-out transaction when they can just keep the BTC and leave the peg-out transaction in the mempool forever?

Second, even if you had a wrapped BTC derivative on the STX chain (xBTC), why should anyone believe that 1 xBTC = 1 BTC? Who or what maintains that peg? As I said above, burning BTC to mint xBTC will cause the value of 1 xBTC to depreciate against BTC over time, since there will be more liquid xBTC than liquid BTC. Even if you could somehow magically force miners to fulfill xBTC holders’ peg-out requests, all this would do is make mining more expensive – miners are losing money by trading xBTC for BTC at parity. If the chain doesn’t just halt due to miners getting priced out by this, then the best-case outcome is that everyone else’s transaction fees will get pushed up to compensate.

The way to ensure that 1 xBTC = 1 BTC is to write a smart contract that makes sure that each xBTC is backed by liquid BTC on the Bitcoin chain. The way you would do this is you’d have a BTC liquidity provider do the following:

  1. Register themselves as a xBTC minter by putting up STX collateral that exceeds the value of the BTC they’ll provide. You’ll need some kind of oracle to make sure that the collateral is always high relative to the BTC provided.
  2. Mint the collateralized xBTC
  3. When a user wants to convert their xBTC back to BTC (peg-out), send a Bitcoin transaction that pays out the BTC, and then mirror that transaction to the collateral contract to prove that they processed the peg-out. If they do this within an allotted window of time, the xBTC are taken out of circulation since they exited. If they fail to do this, then the peg-out requester gets to take STX collateral from them proportional to the xBTC they wanted to exit.

This can all be achieved today without changing the consensus protocol. If the STX collateral they’d lose exceeds the cost to liquidate xBTC for BTC (and this is a big if), the liquidity provider is incentivized to process peg-out requests in a timely manner. If the BTC are ever undercollateralized – i.e. if it’s ever cheaper for the BTC liquidity provider to ignore peg-outs and get slashed than it is to send a BTC transaction – then you’d need to find a way to increase the penalty, or you’d need to pause peg-outs, or you’d need to take xBTC out of circulation. Also, if you really wanted, you could get miners to relay their view of the STX and BTC prices to blocks via a price oracle contract, which other smart contracts (including this one) could use to figure out how much STX collateral is necessary.

1 Like

That’s why I said that surely I was missing a lot :slight_smile: Really good points Jude, I appreciate your response!

Anytime! It’s a difficult but worthy problem to work on. Let us know if you make any more headway!

1 Like