Skip to content

Rejection sampling introduces unreliable gas estimations  #5

Description

@cxkoda

Rationale

The current implementation for drawing uniformly random numbers in a given range is based on rejection sampling, see

for (result = n; result >= n; result = read(src, bits)) {}

The associated gas costs are therefore not fixed but might vary from call to call depending on the required iterations. This makes gas cost estimations unreliable because the state of the random source might change until a given transaction is included in a block. In the worst case, this could lead to failing transactions.

Potential solution

Change to a random number sampling scheme with constant gas cost.
I did not do any proper research on potential algorithms yet, but one that comes to mind would be modulus sampling result = BigUniformRand % n - trading exact uniformity (introducing mod biases) for a constant gas cost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions