stacksgov / grants-program

Welcome to the Stacks Foundation Grant Program. Community members interested in submitting a grant proposal may do so by opening an issue in this repository and filling out the grant application.
140 stars 36 forks source link

Sypool (by @syvita) — the first STX mining pool #83

Closed Zk2u closed 1 year ago

Zk2u commented 3 years ago

repo header gradient

Background

in order to mine STX tokens profitably, it was estimated that a miner needed around 1BTC initial capital to pull a profit (from Daemon Technologies' blog). since then, miner rewards have decreased from 2466STX to 1000STX, changing this some. however, mining is still very difficult for people who don't have this large initial capital. a mining pool 'pools' many people's funds into a single miner, reducing the chance of making a loss significantly. this is what the Syvita Pool plans todo. this allows more people to mine, and increases security of the blockchain.

Project Overview

Syvita Pool is a partially trustless smart contract controlled STX mining pool. a detailed architectural and process overview is available at this repo. the pool will serve any member of the Stacks ecosystem with a minimum of 1000sats (less than $1.

Scope

there are 5 parts to the mining pool infrastructure wise.

  1. the smart contract (on the Stacks blockchain).
  2. the website/UI
  3. the Bitcoin node, used to spend bitcoin with
  4. Stacks node A, running in miner mode and connected to the local bitcoin node
  5. Stacks node B, running in follower mode as a publicly available API.

the web UI will be hosted as a static nextjs site on Cloudflare's edge, alike other Syvita sites. the static site will make API requests to Stacks node B as default. the code for this site will be here.

the Bitcoin node & Stacks node A (the miner) will be hosted on a Mac Mini owned and managed by @pxydn. this will be locally controlled and not accessable to the public internet as the private keys to the pool Bitcoin wallet are held here. the Mac is connected only via a VPN, as to not expose the IP address, open any public ports to the machine and reduce the attack surface. the bitcoin node is Bitcoin Core and the Stacks node is the one created by Hiro

Stacks node B will be run as a VM on Bitlaunch. no private keys or funds are stored on this machine. it will be connected to requests to it via a Cloudflare Argo Tunnel, to protect from attacks. this node runs stacks-blockchain-api, created by Hiro.

both Stacks nodes will be updated as new releases of the Stacks node software are released. Stacks node B will have a 2nd VM booted and connected to Cloudflare until it has caught up with the chain, then traffic will be routed to it via Cloudflare and the other VM will be destroyed. Stacks node A will use a similar method, but will start a new instance on the same machine instead.

the final deliverable will be a functional mining pool running on Stacks mainnet. success will be measured with how much capital is provided to the pool.

Budget and Milestones

i don't need a grant for the development time, only for the initial server costs. ideally this would be in Bitcoin, to protect my pseudonymity (which is needed for this project).

Total Grant Request: $2500

Team

i'm the main developer of the project, but it has had support from @jcnelson at the Stacks Foundation and is backed by the Syvita Guild. i founded Syvita and we're the 2nd biggest developer organisation on Stacks. this project will aid our funding. our github organisation is @syvita

Risks

the main risk is that the pool will not reach the initial amount of capital needed to start mining profitably.

however i used an anonymous survey on the Stacks Trade Telegram channel and the results showed that the community is backing of the project, and that we are very likely to be able to start the pool.

an estimate of initial capital contributed to the pool (from said survey) is $543,000 which is at least 20x the amount we would need to start the pool (based on Daemon's research). we hope this amount will grow over time.

karlzw commented 3 years ago

great project, can't wait for it.

AndrewThebe commented 3 years ago

Great in did lets make it happen

JMKJR commented 3 years ago

Good luck! 👍

falkonprods commented 3 years ago

Yes. I want in!

314159265359879 commented 3 years ago

Thank you for taking on the task of building the first mining pool @pxydn, together with Labs3 members. I think this will be very good for a healthy growth of the Stacks network because it makes mining more accessible.

thambisrinath commented 3 years ago

this is a great initiative and I would certainly back it. However, any estimate on the downside risk? Say you get capital of over 500k, what's the max risk interms of capital erosion and in which scenario could that risk trigger? and what would be the avg. estimated gains?

Zk2u commented 3 years ago

this is a great initiative and I would certainly back it. However, any estimate on the downside risk? Say you get capital of over 500k, what's the max risk interms of capital erosion and in which scenario could that risk trigger? and what would be the avg. estimated gains?

as the capital is relatively large, losses of blocks don't make nearly as much as a difference. Daemon estimated that we would need maybe $20-$25,000 to turn a profit on the new 1000STX per block reward.

effectively, the more cash you have, the more likely you are to make a profit - merely as your losses don't hurt as much (this is the advantage of a pool). assuming capital of $543K that is all spent, at BTC price of $60K we're looking at around 9BTC total spent. this amount will already put the pool in 3rd place in terms of Bitcoin burnt.

this is data from the first 5000 blocks. beware, this was with the additional rewards, so we'll probably see maybe half the gain as what these numbers show. image total bitcoin spent is in satoshis. a miner with ~7.9BTC (the 3rd one) made a 56% profit on their burnt funds. so looking at that and then placing our 9BTC in, i would perhaps guess a 25% return when your funds are burnt.

the larger the pool becomes, the more stable the profit will become. i hope this sorta answers your question :))

friedger commented 3 years ago

The proposal should also include some work to stress tests the contract (to verify that it is ready for production) and the miner node (to verify that it plays nicely with a mining pool).

Zk2u commented 3 years ago

The proposal should also include some work to stress tests the contract (to verify that it is ready for production) and the miner node (to verify that it plays nicely with a mining pool).

we plan todo this, yes! ideally i'll try to break it on my mocknet then the L³ team will heavily test it on testnet before it even reaches production. ideally i would like the code checked over by others.

the miner node will see no different use from how others are using it, except the wallet it mines from will be filling up. i don't think this should affect this, but we'll test this in the testnet phase.

cryptopanter commented 3 years ago

Totally precious project and necessary for the next milestone of Stacks ecosystem, Since Stacking and mining are both some kind of infrastructure for the netwok...but i have a trivial quetsion: what will happen to Node A if that Mac system is lost or damaged?

Zk2u commented 3 years ago

Totally precious project and necessary for the next milestone of Stacks ecosystem, Since Stacking and mining are both some kind of infrastructure for the netwok...but i have a trivial quetsion: what will happen to Node A if that Mac system is lost or damaged?

in the very low chance that this happens, i have various backups of the mnemonic of the bitcoin pool. though the node will stay at home connected via a UPS at all times and won't be moved (unless we move house). it's very unlikely to happen, and if so i'll purchase a new one and set it up with the backup phrase :)

cryptopanter commented 3 years ago

It's a kind of delegation or what?.. I mean the users Btc amount need to leave their address and be sent to you? Or they keep it in their wallet?

Zk2u commented 3 years ago

It's a kind of delegation or what?.. I mean the users Btc amount need to leave their address and be sent to you? Or they keep it in their wallet?

yes. bitcoin has to be sent from the user to the mining pool's BTC wallet, where it will be used to mine the STX tokens

friedger commented 3 years ago

Users have to trust the pool admin that they use the BTC efficiently with mining. Questions about mining strategies are probably out of scope for this proposal.

thambisrinath commented 3 years ago

this is a great initiative and I would certainly back it. However, any estimate on the downside risk? Say you get capital of over 500k, what's the max risk interms of capital erosion and in which scenario could that risk trigger? and what would be the avg. estimated gains?

as the capital is relatively large, losses of blocks don't make nearly as much as a difference. Daemon estimated that we would need maybe $20-$25,000 to turn a profit on the new 1000STX per block reward.

effectively, the more cash you have, the more likely you are to make a profit - merely as your losses don't hurt as much (this is the advantage of a pool). assuming capital of $543K that is all spent, at BTC price of $60K we're looking at around 9BTC total spent. this amount will already put the pool in 3rd place in terms of Bitcoin burnt.

this is data from the first 5000 blocks. beware, this was with the additional rewards, so we'll probably see maybe half the gain as what these numbers show. image total bitcoin spent is in satoshis. a miner with ~7.9BTC (the 3rd one) made a 56% profit on their burnt funds. so looking at that and then placing our 9BTC in, i would perhaps guess a 25% return when your funds are burnt.

the larger the pool becomes, the more stable the profit will become. i hope this sorta answers your question :))

great...this is perfect

Zk2u commented 3 years ago

this is a great initiative and I would certainly back it. However, any estimate on the downside risk? Say you get capital of over 500k, what's the max risk interms of capital erosion and in which scenario could that risk trigger? and what would be the avg. estimated gains?

as the capital is relatively large, losses of blocks don't make nearly as much as a difference. Daemon estimated that we would need maybe $20-$25,000 to turn a profit on the new 1000STX per block reward.

effectively, the more cash you have, the more likely you are to make a profit - merely as your losses don't hurt as much (this is the advantage of a pool). assuming capital of $543K that is all spent, at BTC price of $60K we're looking at around 9BTC total spent. this amount will already put the pool in 3rd place in terms of Bitcoin burnt.

this is data from the first 5000 blocks. beware, this was with the additional rewards, so we'll probably see maybe half the gain as what these numbers show.

image

total bitcoin spent is in satoshis. a miner with ~7.9BTC (the 3rd one) made a 56% profit on their burnt funds. so looking at that and then placing our 9BTC in, i would perhaps guess a 25% return when your funds are burnt.

the larger the pool becomes, the more stable the profit will become. i hope this sorta answers your question :))

great...this is perfect

comment from @314159265359879 in the labs³ channel:

Based on the first 5000 blocks it is easy to overestimate the returns from mining. I think the data from the last 1000 blocks may paint a more realistic picture.

I see returns between 18-7% from the top 5 miners. As you can see there are also miners with net losses, most of these miners have spent a lot less so I think it is because they didn't have enough capital to even out the gains.

There is one miner who spend 3.2 BTC with a net loss of 7.8% in the last 1000 blocks but currently there is no way to tell how much of that was spend on the last 1000 blocks, maybe he was offline for a bit, who knows.

source: https://stxmining.club

we don't really have any solid way of knowing the return until it's live. it's worth noting that the 3.2BTC above is almost 3x less than the initial capital and this will significantly affect chances of a net loss. as previously said, the more the pool gathers, the less the losses will be to the pool and its members

however... (EDIT)

assuming we get around 9BTC, currently miners are spending around 700K sats per block. say the pool does 750K sats per block, it would've used all its bitcoin in 1200 blocks (just over 8 days).

currently, around 2,772,000 is spent per block by all miners, giving the pool (with 750Ksats per block) around a 21% chance of winning.

that's 256 blocks.

256*1000 is 256,000 STX won and 9BTC spent.

at a market price of 4000 sats per STX, that's 10.24BTC earnt back, giving a return of 14% in just over a week.

THIS IS JUST AN ESTIMATE, DON'T TAKE MY WORD FOR IT LOL

RaffiSapire commented 3 years ago

Hi @pxydn , Why not just run a VM? We can give you a AWS VM if you needs one. The grant total works for us and we're excited to see this built, but would prefer to orient it about deliverables. M1. Smart Contract - Jude has feedback (below) M2. UI . Can you flush out what this enables users to do? M3: Should include stress tests as Friedger recommends.

Zk2u commented 3 years ago

thanks for the reply @RaffiSapire :))

Why not just run a VM? We can give you a AWS VM if you needs one.

for the miner node, it requires the unencrypted mnemonic containing all the funds. having those keys touch anything outside my full control is a security risk.

would prefer to orient it about deliverables.

that's great! sure thing.

UI. Can you flush out what this enables users to do?

the UI will enable users to use the pool in a way that's easy for the everyday Joe. asking for a transaction ID and putting a few clicks is a lot easier than sending raw transactions, block details and manually calling the contract functions (though this will be documented and explained in the repo and can be done manually). it just makes it useable for non-techies who don't want to spend an hour trying to use the pool.

Number of addresses claimed.

not sure what is meant by this. @jcnelson can you please elaborate?

People can use an existing BTC wallet to send BTC to the miner (with the appropriate OP_RETURN payload)

some BTC wallets that support OP_RETURN:

i am trying to get BlueWallet to implement this. still a request at this moment.

End-to-end UI for contributing BTC and claiming STX

this was detailed above.

It’s not clear what the trust model here is. Do users just give him BTC and he use it to mine? Or are there stronger guarantees that he can’t just run away with the funds?

yes, unfortunately i haven't found a better way of doing this. by using collateral, profits are reduced and it is not scalable as the pool grows. no, there are not. this is the most trustless way I can think of due to how mining works :)

RaffiSapire commented 3 years ago

Hi, this is approved for $2,500 to be disbursed as milestones:

M1. Smart Contract - 500 M2. UI mockup, please include text that make it clear this is an independent effort, e.g. not stacks branded - 300 M3: frontend built - 700 M4: #3, #4, #5 you laid out at the initial scope, PLUS stress testing and results of those - 1000

please email me at raffi@stacks.org to get onto bill.com

Zk2u commented 3 years ago

PS: I have updated the naming/links to comply with the labs³ -> Syvita rebrand :D