I'd like to just see a version released with hardcoded rules. If you are having a hard time moving forward, adding complexity will not help.
If you want reconfigurable rules, do it via parameters. Not code. Interpreting code etc just seems like a big rabbit hole + security issues.
Break it down into parameters that lotterys have. I'll put a few off the top of my head.
1. Period of drawing.
a) By block count
arg1 - block count
b) By ticket purchase amount
arg2 - ticket amount
c) Both a & b but whichever is hit first.
2. Payouts
a) All prize pool is paid per drawing
args[] - payout info encoding
b) Cumulative jackpot
....
For payouts let me go through an example.
X is the number of balls in the pool of balls.
Y is how many balls people choose for their lotto pick and how many balls are chosen to select a winner. (Always same value)
So list payout share for choosing Y balls, payout share for Y-1 balls ........ payout shares for 1 ball
Example -
X = 50, Y = 5 (Actually X doesnt matter, except when figuring out your payout schedule)
'
(*Note, I am using shares in a manner different from bitshares/stock)
So Y = 10000 shares, Y-1 = 100 shares, Y-2 = 10 shares Y-3 = 5 shares Y-4 = 1 shares
So if prize is not cumulative you add up the total shares and pay them out proportionally.
So the 5 balls drawn composing Y are 1,2,4,10,20 (winning #s)
One person chooses 3,2,4,10,20 so they get the Y-1 value (4/5 balls) or 100 shares.
2 people chose 10,X,X,X,X so they get Y-4 value of 1 share. (Only their 10 matched)
So that is 100 + 2 * 1 = 102 shares.. So person who hit 4 numbers get 100/102 of the prize pool.
The 2 people who hit 1 number get 1/102. Of course some portion goes to the lotto dac too.
If you have cumulative jackpot option then perhaps the payout vector is different and only Y through Y-2 counts, but never give Y-1 or Y-2 all of the prize pool and have the rest of the pool roll over until someone hits all Y balls.
This sort of thing allows you to give all manner of lotteries without code. Lotteries are really simple. There should be no need for interpreting code off blockchain. Please.
Enforce sanity. Each payout with less matching balls is paid less. Put some limits on the values and you have a pretty simple ruleset which can probably closely emulate the vast majority of lotteries.
Hope this makes sense. I'm tired.
How you will have competing lotteries I am not sure, but I just can't imagine interpreting code in a VM to be anything but a huge headache with little upside. The complexity of lottos does not begin to justify that approach.