-
Notifications
You must be signed in to change notification settings - Fork 101
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
[AIP-41][Discussion] Move APIs for public randomness generation #185
Comments
Hey @alinush, would love to connect and help give insights here. |
Hey @JacobADevore, great, thank you! Would you mind sharing your thoughts here, in order to start a public discussion that encourages others to participate as well? |
Sounds good @alinush! I wanted to inquire about the exact specifics of the AIP. Currently, the spec declares functions that pass in parameters such as a seed. It would be great if you could specifically say where the randomness is derived from and give some more details. The current implementation states it uses 1.) Calling contract 2.) Seed; both are predictable which in turn wouldn't generate randomness. Maybe I am missing something, but some more context would be great. |
@JacobADevore according to the AIP document...
So this is mostly just about the methods the module will expose, rather than about how the random generation will be done:
cheers! |
Really appreciate you folks taking a close look at this! Indeed, as you can see, the current AIP status is But @alilloig is right: this AIP assumes an underlying on-chain randomness implementation (e.g., the validators run some randomness beacon protocol; pick your favorite!) and focuses on what the exposed API to Move developers should look like. In that sense, the However, as I type this, I wonder whether we should get rid of this |
@alinush you are probably right, as a smart contract developer I don't really care from what seed my random numbers come from, just care about having access to them in the simplest possible way |
Indeed. And using external randomness, as we explored in this drand-based lottery example, is quite awkward to (1) implement by developers, (2) use by users, since someone has to post the external randomness, and (3) to audit by external entities due to subtle timing assumptions. |
Understood, I appreciate you clearing that up for me. What do you think of exchanging Just a few thoughts. I would love to hear what you guys think. |
That's an interesting idea! Would you still keep Either way, I like the idea of removing the seed and relying on amplifying the randomness as the unique way of generating multiple pieces of randomness. Another possible simplification could be the use of a |
I've actually just updated the AIP. You can find it here. It should now be fully-contained. I'm curious about the open question O1 there, on how to deal with repeated calls to |
Very well written AIP @alinush! Thoughts on removing Think this would be a better DX than having to pass in an empty vector for generating randomness. Removing a Randomness object to be passed into the function generating multiple randomnesses seems like a better DX as well. Updated: |
Thank you @JacobADevore and glad you found it well-written! (I tried!) Regarding option (c), you would have different calls to That option is interesting to ponder as it would be the simplest. I wonder if developers would be surprised by that kind of non-deterministic behavior within a single TXN's execution and/or if it creates any security issues. |
I wouldn't be opposed to either or, I would say allowing the user to generate within a loop is valuable from a DX perspective but I do see the risks from a security perspective. Maybe we can get some more insights from the Aptos team with this specific question at hand. |
When you say "generate within a loop", do you assume the option(c) |
Correct |
Out of curiosity, why aptos_std vs aptos_framework? I actually don't know how we determine which thing goes where but I notice other consensus-determined value retrieval modules (e.g. timestamp) are in aptos_framework. I think the API to the module looks great, I have almost no changes to suggest. I assume it is omitted on purpose for brevity, but explanations of things like "amplification" would be helpful. While I was reading something that came to mind is it'd be nice if there was a variant of In the developer platform section you mention how we could make the randomness publicly verifiable. This could provide a nice easy API for verification. Have we considered view functions that might help with this? It seems like some key functions could be view functions, like |
what is the motivation behind making |
Thank you @banool and @MoonShiesty! @MoonShiesty, the motivation was to prevent developers from accidentally generating identical randomness for two different events. Note that reusing the randomness is still possible but must be made explicit: i.e., once the However, I think this this So I've just pushed a PR to move away from it and more towards a Rust-like RNG API. Until it merges, you can see the new API here. |
@banool regarding why |
What is the purpose of the generic type param on the
|
Ugh. That... is a typo! Thank you. Fixing here. |
Updated the AIP: Added a test-only function to set the seed (entropy) of the RNG during testing, which should be useful for reproducing bugs:
|
why does calling module matter? Could TXN be enough? |
What is the purpose of exposing
|
I don't think it does. I think what's more important is that each time an RNG is created via a call to I was a bit worried that TXN hashes might not actually be unique due to a scare I once had with Bitcoin TXNs, where coinbase TXNs could actually have the same hash. So it might be worth mitigating against such (current or future) surprises in our design. |
I think you're right: I don't see anything wrong with that approach either. It seems to lead to an even easier-to-use |
i was thinking that it's possible to mix in |
PSA: AIP-41 has recently been updated to v1.2. The major changes are further simplifications to the API and countermeasures against so-called "test-and-abort" attacks. See changelog here. |
In the lottery example, it's mentioned that any one can submit the txn to pay some gas and reveal the winner. But are they incentivized to do so? Somehow Drand-based lottery can be designed to avoid this problem: the winner knows they are the winner, and are incentivized to claim the reward. |
That's a good point. The caller of I guess we can change the code to send a small chunk of the winnings to the caller of (For this, we'd have to pass in a |
I agree that DApp developers can fill the gap in their app-specific way. I guess I'm more wondering how many dapps may benefit from drand style more than on-chain style. Also how many existing things need to be changed. One thing I can think of is that Petra wallet will no longer be able to show the balance diff preview before user click "sign". |
I wonder if both style can be provided.
They can come from the same source. |
I think it would be nice to have an API standard for verifying off-chain secure randomness & it would have the advantages you mention. However, due to the plethora of off-chain randomness beacons (e.g., drand, SupraOracles, Chainlink, etc) that is probably best done as a separate effort in its own AIP. |
I would like to ask the |
Nope, not yet! |
Note: The current v1.2 version of AIP-41 is here.
Short summary
This AIP proposes a new Move module called
aptos_std::randomness
which enables smart contracts to easily and securely generate publicly-verifiable randomness.The proposed
randomness
module leverages an underlying on-chain cryptographic randomness implementation run by the Aptos validators. This implementation, however, is outside the scope of this AIP and will be the focus of a different, future AIP.The only thing this AIP does assume of the on-chain randomness is that it is unbiasable and unpredictable, even by a malicious minority of the validators (as weighed by stake).
Proposed API (last updated August 11th, 2023)
The text was updated successfully, but these errors were encountered: