Implement the access to the transaction index.#6257
Conversation
| /// The index of the current transaction within its block. | ||
| /// | ||
| /// Combined with the chain ID, application ID and block height, this can be used by | ||
| /// smart contracts to derive a deterministic seed (e.g. for pseudo-random number |
There was a problem hiding this comment.
I would remove the part about the usage for implementation of PRNG. I don't even think that's correct.
There was a problem hiding this comment.
Ok, to removing the PRNG usage.
But why do you think this is wrong?
There was a problem hiding this comment.
If you can predict the number generated (and here you can since as the chain owner and block proposer you control all the variables) then it's not a very good source of randomness – you can predict the numbers it generates and then every game is "rigged" (no randomness).
There was a problem hiding this comment.
I do not make any claim of cryptographic security.
The use case I was thinking is for coinbase access. If we send a request that got rate-limited, then sending it again can get you the cache, so the same values. If we add a random entry, then we can bypass the cache.
Now, can coinbase or cloudflare use this kind of information to predict the next call and avoid it? Yes, in principle. Would they do it. I kind of doubt it.
Motivation
The transaction index is a nice invariant to have available when running a smart contract.
Fixes #2411
Proposal
In the killed PR #5606 a random number generator
was proposed but this was not the right design. Here we expose the transaction index which allows building
random number generators.
RNG have their use since using random number in some API queries can disable their caching.
Test Plan
CI
A fixture test has been added which demonstrates the two use cases:
Release Plan
This is I think breaking with
testnet_conway.Links
None.