Skip to content
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

[Feature] Adding a pseudorandom number generator function to ChaCha that takes in Aleo Address and a uint64 as parameters to generate extremely unrepeatable unique IDs #27968

Open
harshnambiar opened this issue May 29, 2024 · 2 comments
Labels
feature A new feature.

Comments

@harshnambiar
Copy link

🚀 Feature

As discussed with Pranav on the dev hour call, the function should work similar to the normal ChaCha rand function, but take three arguments:

  1. The address of the caller
  2. The address of the recipient
  3. A count value that is an integer

Using these a pseudorandom Field will be generated that is so unlikely to be repeated that the probability of it repeating never exceeds 10^(-29)

Motivation

The reason this is important to us is because we want to map something to both the recipient and the sender in the form of Aleo mappings, and such unique unrepeatable IDs would help us achieve that. Each transaction in our Aleo program would lead to one of these IDs being created, hence it is better to do this inside the Leo code itself.

Implementation

Assuming the implementation used is similar to what we have so far used at the javascript layer, the following code just needs to be converted to Rust in the base library for this to work.

Are you willing to open a pull request?
No!

@harshnambiar harshnambiar added the feature A new feature. label May 29, 2024
@d0cd
Copy link
Collaborator

d0cd commented May 29, 2024

The Aleo Virtual Machine (snarkVM) allows users to seed the ChaCha::rand function with user-defined data. This functionality needs to be added to Leo.

Note that the AVM seeds the default implementation with the transition ID, which is a field element. The probability of repetition is approximately 2^(-253) which is already lower than the above threshold.

@harshnambiar
Copy link
Author

The Aleo Virtual Machine (snarkVM) allows users to seed the ChaCha::rand function with user-defined data. This functionality needs to be added to Leo.

Note that the AVM seeds the default implementation with the transition ID, which is a field element. The probability of repetition is approximately 2^(-253) which is already lower than the above threshold.

That might be true but assuming the same contract is used over the entire lifetime of the dapp, then the probability of repeats will keep stacking. We could avoid this by having the first 16 digits of the ID as the timestamp, and the remaining digits as the random number generated using ChaCha::rand. This could be implementable if we can make another rand function in the ChaCha library that takes the timestamp into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature.
Projects
None yet
Development

No branches or pull requests

2 participants