elements icon indicating copy to clipboard operation
elements copied to clipboard

RPC example or tutorial opcodes enabled by liquid

Open afeezaziz opened this issue 2 years ago • 1 comments

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

afeezaziz avatar Jan 19 '24 09:01 afeezaziz

Is there a way to test this function?

afeezaziz avatar Jan 24 '24 16:01 afeezaziz

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 avatar Sep 17 '24 12:09 delta1