-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mechanisms for adding randomness to a subnet #909
Comments
Hey @tactical-retreat , thanks for creating this issue. The long term plan is to utilize the validator set to provide a source of randomness for any VM to use, which we would then use to set the value served by the We're not planning to add any precompiles to support randomness in the meantime, since we'd prefer not to lock ourselves in to maintaining such a solution that we would want to replace. If you want to fork Subnet-EVM and modify it to add randomness, then.. Option 1: this seems reasonable. This puts the trust on the block producer to use a random number. If that works for your trust assumptions, then I don't see an issue with this and this sounds like a fairly lightweight and easy to maintain solution as you mentioned. Option 2: it seems like there may be a few problems with this suggestion. afaict the suggestion here would be to pre-compute all of the values by hashing the result repeatedly, which would allow anyone to predict the whole sequence of values unless I'm misunderstanding. |
Adding a source of randomness is definitely something that we are thinking of. I'll try to post a more detailed write up on this issue shortly later this week... |
@joshua-kim sounds good, look forward to reading it. @aaronbuchwald re: the trust on block producer, I agree, but that's not a concern for this use case. I've already started messing around with this version. I thought it was working but I managed to bork something during testing this morning, I'll fork the repo and publish some changes / notes on what I'm trying, maybe tonight. Re: the verifiable randomness, the idea is that you start with a seed (lets say '0' for this example, but more random in practice) and then hash that repeatedly to produce the set of random data. And then REVERSE it. So you have:
Then you play back the values from the end of the array. So in practice you return This prevents the values from being guessable, while still making them verifiable. If you have the series of random numbers provided by the EVM, you can just sequentially apply the hash fn from most recently provided all the way back through oldest provided to verify that the sequence is fair. But lets put that aside. The list could be a truly random list of numbers with no connection and no verification properties. Mechanically, is this is an abuse of |
Ah I see, I misunderstood. This would be fine to put in imho - I'd recommend against this strategy since it seems a bit brittle. If you are ok with trusting the validator set, trusting the block producer to set the difficulty field with a random value, seems like a better solution. |
Enabling difficulty as a random value was pretty straightforward. Let's just ignore all the stupid things I did along the way. |
So adding a source of randomness is definitely something that we're thinking of. Adding it natively into the protocol directly (say a VRF field in the block header) as opposed to having it built as a third-party subnet is something we are considering. There's a few ways we can go about adding random-ness source - ideally we'd want something verifiable and not trivially gameable. Here's a few ways of generating randomness and some thoughts on them:
(3) and (4) seem to be the most likely candidates for a native on-chain randomness source if we do decide to go for it. |
Context and scope
I'd like to spin up a subnet which can securely provide randomness. It's fine if this has to be done via a precompile.
I'd appreciate any feedback on these proposed options, or guidance towards a better option.
Discussion and alternatives
Option 1: Random number in difficulty field
The first thing I thought of was to just stick a random number in the
difficulty
. I see this has been hardcoded to 1 in subnet-evm, and thetotalDifficulty
hardcoded to the block number.It looks like I could just update
DummyEngine.FinalizeAndAssemble
to set a randomdifficulty
? I don't seedifficulty
validated inDummyEngine.Finalize
, but I'm not sure if this would subtly break anything.This seems like an invasive change compared to a precompile, but relatively simple to maintain. Not verifiable.
Option 2: Read precommitted random numbers from a file
Seems like precompiles have access to the
ChainDataDir
value. I was thinking of:This is a less invasive change, and has the advantage that the randomness can be verified (by recomputing the hashes). Slightly more annoying in that we have to provision the files on every validator.
Not sure if this is an appropriate use of
ChainDataDir
though.The text was updated successfully, but these errors were encountered: