Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Simulation is not deterministic due to GenSignedMockTx #12373

Closed
4 tasks
adu-web3 opened this issue Jun 28, 2022 · 0 comments · Fixed by #12374
Closed
4 tasks

bug: Simulation is not deterministic due to GenSignedMockTx #12373

adu-web3 opened this issue Jun 28, 2022 · 0 comments · Fixed by #12374

Comments

@adu-web3
Copy link
Contributor

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
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 a pull request may close this issue.

1 participant