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

RPC example or tutorial opcodes enabled by liquid #1313

Closed
afeezaziz opened this issue Jan 19, 2024 · 2 comments
Closed

RPC example or tutorial opcodes enabled by liquid #1313

afeezaziz opened this issue Jan 19, 2024 · 2 comments

Comments

@afeezaziz
Copy link

"DETERMINISTICRANDOM" is something that of interest but I would like to see how it can be done by RPC.

@afeezaziz
Copy link
Author

Is there a way to test this function?

@delta1
Copy link
Member

delta1 commented Sep 17, 2024

It's not a function nor RPC, it's an opcode ie. it's a specific byte (0xc0 = 192), which when included in bitcoin script has a specific function.

When this opcode is being executed by the script interpreter, it appears to work as follows:

  • the stack must have at least 3 items, from the top of the stack these are: random seed, min value, max value
  • if min > max, fail
  • if min = max, push the min value back onto the stack
  • initialize a CSHA256 hasher with the seed provided from the stack
  • use this hasher with a deterministic algorithm to generate a random number between the given min and max
  • pop the 3 stack items and push the deterministic random number onto the stack

For a given (seed,min,max) this will always produce the same random number (it is deterministic)

@delta1 delta1 closed this as completed Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants