Skip to content

bug: Simulation is not deterministic due to GenSignedMockTx #12373

Closed
@adu-web3

Description

Summary of Bug

The simulation is not deterministic because we use a standalone random generator in GenSignedMockTx:

func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
	sigs := make([]signing.SignatureV2, len(priv))

	// create a random length memo
	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100))
...
}

This random generator use a different random seed from the simState.Rand, while GenSignedMockTx is widely used in x/{module}/operations.go to generate sdk.Tx.
This means even with the same random seed, the simulation could generate txs with different length of memo.
Therefore, ConsumeTxSizeGasMiddleware could consume different gas while executing the tx, which leads to non-deterministic appHash.

Version

master@450cd7fc8708ccb0fa21f05e251d9804a2063b79
release/v0.45.x

Steps to Reproduce

  1. change `NumBlocks` to 1 in Makefile `test-sim-nondeterminism` section.
  2. make test-sim-nondeterminism.
  3. test failed.
____

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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