[PRE-CHIP/Idea] Establishing the viability of OP_LOTTERY [Incentivizing donations and sales through utilizing human greed]

Any opcode that “reads” the block header will also change in validity and outcome based on which block it’s included in, and so will be a nightmare (if not outright impossible) to manage in mempool - it cannot be chained, and will need to be re-evaluated every block.

Thanks for valuable input.

I will now think about how to solve this issue.

1 Like

I generally like the idea, but I’ll try to explain why I’m unsure such functionality should make it into consensus. I’ll start with general considerations, diving down into more specific later.

OP codes are generally understood to be basic building blocks from which complex functionality can be built. This proposal has a rather specific scope. General concepts are things like ADD, MUL, etc that can be harnessed into an infinite number of usecases. This seems to have one single usecase.

It also implicitly relies on a fair source of randomness, which is a whole different problem unto itself.

“The owner of the receiving address is the “lottery owner””, so if they are the owner then they should be able to spend (steal) the amount, instead of giving it to the lottery.


I am sympathetic with the use case, but I think that it can be solved, with a varying degree of trust, by using SLPs and a centralised server - since you still care about your own reputation, you’ll be honest about the lottery. This could be essentially made fair using some variant of the “provably fair” procedures of gambling sites. Senario: an online shop is giving one SLP token for each 10$ spent, and every week they send a jackpot to a random utxo containing the token.

Or maybe some smartBCH bridge nowadays.

I do think that, if a fair source of randomness is available, a suitable smart contract could be created (or maybe not, idk). But I still feel that this functionality is too specific in a general purpose setting.

Thanks for your input, @mtrycz

Regarding some of your points I can address right now:

Yeah, “OP_LOTTERY” is not an opcode, just a generic temporary name for this functionality. It does not have to actually be an opcode.

I agree, perhaps it would require some other significant changes, opcodes may not be enough.

This is why I posted it here as a pre-chip so I can get your input and criticism to find out whether this can be refined into a valid idea for the future.

I am sorry, but this is unacceptable. It has to be completely provably fair and require no centralization/trust/service.

To make any sense and bring the benefits I think it could potentially bring, this proposal would have to run on Bitcoin(Cash) blockchain itself.

Above point also applies.

I aim for a “general purpose” setting, because my goal is to make every shopping BCH transaction a lottery, possibly.

It could enable automated blockchain-based payback scheme for every merchant everywhere, worldwide with just a click.

So I think the possible ramifications of this proposal (if it works in a decentralized fashion and doesn’t strain the network) are basically insane. It could be a total game changer for BCH.

Votes by transaction count and votes by satoshi sent are essentially the same vote system. Because you cannot prevent someone from sending multiple transactions (either be it using the same address or multiple addresses controlled by the same person), transaction counting comes down to how much satoshi they are willing to send. The only difference being that rather than in a single transaction, it is in multiple. This method would bloat the blockchain a lot with small transactions for the sole purpose of gaining a lottery advantage. Attempting to track people potentially splitting their coins into multiple addresses prior to entering the lottery would require chain analysis which cannot be done from within the blockchain, you will need some other central server. I do not recommend doing it by transactions sent.

Using the total satoshi amount sent from someone would prevent the bloat and would be the same system as a normal lottery or raffle. The more money put in the higher the chance of winning.

It seems like it might be possible to do this lottery system using some sort of convenant script as previously suggested by imu. Although i think the viability is tied to the number of lottery participants and going over some sort of threshold would break the lottery system due to script system constraints.

1 Like

Sorry for not answering too long, I had some significant life issues to deal with.

Regarding your points, @Griffith

Votes by transaction count and votes by satoshi sent are essentially the same vote system.

I am not entirely sure we are talking about the same thing. Perhaps this is my fault, I should have been more clear?

  • When I meant “vote by transaction count” I mean by the total number of transactions, completely disregarding sent value. So 100 votes of 1 satoshi each would be worth the same as 100 votes with 1 BCH each.

  • When I meant “vote by value” I meant that 1 vote of 1 BCH is worth the same as 100 000 000 1-satoshi votes or so.

Using the total satoshi amount sent from someone would prevent the bloat and would be the same system as a normal lottery or raffle. The more money put in the higher the chance of winning.

This is exactly my point. So far I don’t see how such a system could be easily abused, but I have probably not analysed all possible scenarios yet.

It seems like it might be possible to do this lottery system using some sort of convenant script as previously suggested by imu.

I will get to implementation after I confirm such a system is possible to do at all and it doesn’t have any serious downsides.

Ah, and obviously after I write a proper CHIP.

Yes, I understand this. I was only trying to point out that because there is no way to accurately determine, without chain analysis, if two addresses are submitting votes for the same person, these two systems are the same. This is an illusion of choice.

Correct, however assuming cheating is not incentivized: meaning it is not more profitable to cheat than to do “honest” lottery, then it it does not change anything in the ultimate outcome.

Also, there is no point in even trying to find out whether a lottery is honest or not, because chain analysis is not 100%-proof and that is out of the scope of this idea anyway.

it is irrelevant whether the lottery is “rigged” by the lottery owner or not. Instead of trying to police every lottery being honest, incentives should be set up in a way that it is not profitable to cheat.

OK, so I gave this issue some thought.

If I understand this right, there are 2 sub-issues here:

  • Because there are multiple possible outcomes of a block due to there being micro-splits in the blockchain structure, everything from a block would need to be re-calculated for every possible block variant
  • Due to there being multiple variants of each block possible, it will become extremely hard or impossible to chain such variants with each other, due to there being exponentially rising number of possible scenarios due to random block headers changing on each subsequent block

Hmmm, this proposal would indeed be difficult to or impossible to do if we use data from the current block (the same block that would contain lottery result).

So, a possible solution would appear to be to solve lottery later, X blocks after the lottery votes were passed and confirmed. Perhaps the default for X could be the same value miners get their payout after (was it 100 blocks?).

The exact scenario I mean is:

  1. Lottery Host announces in block 999 the lottery will happen at Bitcoin Cash address qpAAABBBCCD, starting at block 1000, ending at block 2000.

  2. Lottery participants pay for goods and services by sending their BCH to the lottery address, and their transactions end up included and confirmed by the network in blocks 1000 to 2000.

  3. The network (nodes) consider lottery status as “ENDED” in block 2001.

  4. The network (nodes) wait for 99 more blocks in order to execute the lottery.

  5. The lottery is executed in block 2100 and the winner is selected, the random seed to make the lottery “deterministically random” and fair is taken from last lottery participation block, meaning block 2000.

5a) Alternatively, the random seed can also be taken as a sum from SHA256(BLOCK2000…BLOCK 2099) for more randomness. But would that really be any better or more random? Not sure, but I sense that probably it won’t. I am not that good at crypto math to be sure.


I think this should do it.

I await your input @im_uname. Did that solve the issue?

I’m not @im_uname , but I think if it is known in advance that block 2000 is “the decider”, then some miner can try grind it to tilt the lottery outcome in their favor.

Maybe this will not be a big problem in practice, but I think there would be ways to harden a blockhash-based randomness scheme against such gaming.

My suggestion would be to use hash data from more blocks. That would make it increasingly expensive for miners to game the scheme.

For example, do a kind of random walk back through block hashes based on some block hash, in your example the one from block 2000.

Use the hash to decide how far to jump back to get the next block to inspect. Do this a few times (maybe 10 or 20 times) and it should be very hard for a miner to construct such a sequence of blocks in the past history that would would allow them to game the outcome. Why? because you can make it potentially go back quite far to beyond when the lottery was announced. And you can’t game the future unless you know what lotteries are going to be announced. The only alternative is to allocate lots of hashpower generally to BCH, which is also expensive.

This is just a showerthought on how to address the gameability of blockhash-based randomness.

Generally I like the idea of using lotteries to incentivize use of Bitcoin Cash, even though I seldom play the lottery. Or maybe I do every time I go outside :smiley:

1 Like

I’m not @im_uname , but I think if it is known in advance that block 2000 is “the decider”, then some miner can try grind it to tilt the lottery outcome in their favor.

Maybe this will not be a big problem in practice, but I think there would be ways to harden a blockhash-based randomness scheme against such gaming.

My suggestion would be to use hash data from more blocks. That would make it increasingly expensive for miners to game the scheme.

For example, do a kind of random walk back through block hashes based on some block hash, in your example the one from block 2000.

These are very valuable suggestions, thanks @freetrader

It will take me a lot of time to finsh designing/coding this idea anyway, so I might as well do it “right”, in a way that cannot be gamed at all.

By incorporating your input I believe it will be possible.

Generally I like the idea of using lotteries to incentivize use of Bitcoin Cash, even though I seldom play the lottery. Or maybe I do every time I go outside :smiley:

Good to know :slight_smile:

Now that I have the opinions of most major active developers I conclude that the idea is probably not dumb, retarded, controversial or technically infeasible, therefore I will first conduct an incentive analysis in a form of excel spreadsheet and a chart and then I will start writing the actual proper CHIP.


Again, thanks everybody for your valuable input.

1 Like

If you want to make every transaction a lottery, then you can use transaction fees for that. All that is needed is some miner running the lottery, that miner can just collect all fees and send them to the winner. Mining is in practice some kind of lottery: all miners are trying to collect fees and only one miner can get the whole pot sitting in mempool. For now, there are no restrictions, any miner with block hash below the target can get the whole pot. Just change that rule and restrict who should get the coinbase transaction and you will get your lottery. Then, everyone could download that block and make sure that the coinbase transaction is sent to the lottery winner.

It can be easily solved by some script like “123456 OP_GETBLOCKHASH” that will just return the hash of the block 123456. If that block number is from the future, then that output could be automatically timelocked to that block number. In a block 123456 that hash will be known and in all coming blocks it would be the same, unless block 123456 would be stale, but then that hash could be changed only once per chain reorg.

No, because if you have a function f(a,b,c,d) that takes a, b, c and d and produces some result, for example from 0 to N-1 and based on that there is one of N winners selected, then it is possible to game the whole system just by constantly changing d-value. Each block header contains the hash of the previous block, there is no point in hashing last N block headers, because they are hashed during chain creation. If block hashes will be the source of randomness, then miners will always win, because they can create as many non-standard transactions for free as they want, so they can put some coins in the lottery without sending their transactions to other mempools in P2P network, and they can mine only the blocks when they win.

1 Like

@ShadowOfHarbringer I made a little competition for the Introspection upgrade, that demonstrates some simple uses of the opcodes and reactivated OP_MUL.

It got me thinking whether a lottery is possible, and a simple/limited variant may be, however I think some awesome “native” rolling and “always on” lottery could be created using CashTokens/Group, and your thread will hopefully inspire a contract to celebrate May 2023 upgrade :smiley:

2 Likes

Oh, my browser crashed and I just noticed this now.

It’s like a bounty to use the new features of BCH first, it will inspire some participation and usage.

Great idea!

1 Like

Problem are dependent chains of TX-es which would also become reset and make a mess. Same holds for coinbase outputs which is why they have maturity… so that opcode should also be limited to accessing blocks that have matured, and it could be made more useful:

I have already solved this problem.

It is easily solved by deciding the result of the lottery later, not in the same block.

100 blocks delay, like the miner payout delay, would be probably best.

1 Like

yup, I say the same in the other topic :wink:

I had an epiphany about using block headers as entropy source: not all blocks are “worth” the same. Consensus forces blocks to meet the minimum target (hash must be at least this low of a number), but it’s all subject to variance: some blocks will happen to meet it near the edge, some blocks will be 10x or even 100x away from the target. What if lottery requires a much harder block to be the one that sets the RNG?

100x.

This means lottery can be resolved only when such a block happens to land (once every 100 blocks, but it could take 200 or 300 blocks – variance!), but for e.g. a weekly lottery this is enough. Basically, the higher value the lottery manages, the less often you could safely pick winners.

So a first block lands, lottery contract settles, can some other miner replace the RNG? He’d need to mine at 100x difficulty!


Worked out some details with GLM-5.3:

  • Superblocks: the 100x threshold (“superblocks” in NIPoPoWs terms) sets the settlement rate (mean ~100 blocks, geometric tail: 13% over 200, 4.9% over 300) and prices manufacturing an outcome at ~m \cdot N blocks of energy. It does not price peeks or reorgs — those are controlled by other dials.
  • Peek-and-withhold is the real attack: every block is a free 1-in-100 peek; withholding an unfavorable qualifying block costs ~1 block reward regardless of m. Marginal bias \approx 1/(1-q) — m cancels. Bounty must satisfy B + R \geq s_{\max} \cdot P, so it scales linearly with the prize.
  • Replacement is not 100x-hard: reorging the settlement is standard confirmation-depth economics; BCH’s 11-conf auto-finalization covers it for any q < 0.5 ((q/p)^{10} race odds). No need to wait ~m confirmations — confirmations never had to scale with m.
  • No fallback rule: lottery slows until a qualifying block lands. If a hard deadline exists, it triggers refunds (manipulation-neutral), never a weaker RNG.
  • VDF over the seed kills the peek: outcome = h^{2^T} \bmod N; by the time the withholding miner can evaluate it, withholding costs him stale blocks. Constant-factor hardware edge (ASIC vs commodity, ~2–10x) is absorbed by setting T with slack — unlike PoW, capital can’t buy wall-clock time. With BigInt + bounded loops + functions, Wesolowski verification (one modexp) is native Script; add a Pocklington certificate for the challenge prime e = H(x,y) — the primality check is where the soundness lives, fixed-e is trivially forgeable. RSA modulus via MPC ceremony over class groups (simpler script, acceptable threat for a lottery).
  • With a real VDF, the bounty collapses: withholding becomes pure griefing/delay, not steering — nominal bounty, prize-independent.
  • Residual threat: a majority attacker always owns the chain; m just makes each reroll cost ~m blocks of exposed fork time. That’s as good as single-chain PoW gets.
  • Result: m prices manufacturing, finalization prices replacement, the VDF prices peeks — three orthogonal dials, and the jackpot sizes you can safely run scale with the last two, not the first.
2 Likes

Thanks for reviving this long-dead research topic, oh mighty :sparkles: Necromancer :sparkles: !

No, but seriously - thank you :+1::+1:, because I almost forgot I invented this.

Regarding your argument:

This is generally a very good idea in general, however the 100x ratio might be dangerous (too high) because it could cause some unpredictable consequences (like miners actually fighting to mine that block for some reason I cannot perceive yet and stopping mining normal blocks with 1x difficulty).

I am sure we could come up with some “safer number”.

So I understand the idea here is to allieviate the possible cheating issues with increased difficulty, so it is harder for the miners to cheat?

I understand the concern, however I am not sure if this is necessary. You can construct the lottery in a way where the winning block hash decides which other blocks and transactions included in these blocks get picked to decide the winner (get inserted into the final hash that decides the winner). This way, cheating is made so incredibly hard, it is completely impractical to cheat because you would have to clverly craft 1000 consecutive blocks, including transactions in them.

Or did I understand your intention wrongly?

I was thinking about something else where I had to ponder PoW targets and got reminded of this, can’t believe it’s already been 4 years since this thread. Anyway, then I remembered these talks, and wanted to note this down and went searching for the thread. I think someone else was more recently bouncing this lottery idea, but maybe it was on Telegram.

Right. And Freetrader was still here :cry:

1 Like