Skip to content

Random Number Generation Issue Post Titan Upgrade #1367

@kaijudev

Description

@kaijudev

Describe the bug
I'm seeing an issue after the Titan upgrade where contracts that use random number generation in solidity are not working. The transaction gets submitted but never gets picked up by the blockchain or indexed. The cro value and gas seem to be taken out of the account though. I can't provide a tx hash since it is never indexed. This issue seems isolated to using a random number generation function in a contract from what I can tell. Potentially one of the properties off block?

Here is an example of a random number generation function that causes the issue:

function getRandomAvailableTokenId(address to, uint updatedNumAvailableTokens)
        internal
        returns (uint256)
    {
        uint256 randomNum = uint256(
            keccak256(
                abi.encode(
                    to,
                    tx.gasprice,
                    block.number,
                    block.timestamp,
                    block.difficulty,
                    blockhash(block.number - 1),
                    address(this),
                    updatedNumAvailableTokens
                )
            )
        );
        uint256 randomIndex = (randomNum % updatedNumAvailableTokens) + 1;
        return getAvailableTokenAtIndex(randomIndex, updatedNumAvailableTokens + 1);
    }```


**Expected behavior**

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
Any

**Smartphone (please complete the following information):**
Any

**Additional context**
Add any other context about the problem here.

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