Skip to content

Implement the access to the transaction index.#6257

Open
MathieuDutSik wants to merge 3 commits into
linera-io:mainfrom
MathieuDutSik:transaction_index
Open

Implement the access to the transaction index.#6257
MathieuDutSik wants to merge 3 commits into
linera-io:mainfrom
MathieuDutSik:transaction_index

Conversation

@MathieuDutSik
Copy link
Copy Markdown
Contributor

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:

  • That a transaction is the first one.
  • That a RNG can be built on that.

Release Plan

This is I think breaking with testnet_conway.

Links

None.

@MathieuDutSik MathieuDutSik marked this pull request as ready for review May 8, 2026 08:47
Comment thread linera-execution/src/lib.rs Outdated
/// 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the part about the usage for implementation of PRNG. I don't even think that's correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, to removing the PRNG usage.
But why do you think this is wrong?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Successfully merging this pull request may close these issues.

Allow enforcing that a transaction is the first one on the chain.

2 participants