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

Exporting empty state leads to a segmentation fault #1834

Closed
4 tasks
amrali opened this issue Jul 26, 2018 · 10 comments
Closed
4 tasks

Exporting empty state leads to a segmentation fault #1834

amrali opened this issue Jul 26, 2018 · 10 comments

Comments

@amrali
Copy link

amrali commented Jul 26, 2018

Summary of Bug

This probably low priority, but at [email protected] running gaiad export right after gaiad init causes a segmentation fault trying to deference a garbage memory address.

$ gaiad export
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x461e21e]

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).NewContext(0xc420a360c0, 0xc4200c5f01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:200 +0x5e
github.com/cosmos/cosmos-sdk/cmd/gaia/app.(*GaiaApp).ExportAppStateAndValidators(0xc420b421e0, 0xc420c0c300, 0x4c8a640, 0xc42000e008, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/app.go:191 +0x6a
main.exportAppStateAndTMValidators(0x4c815c0, 0xc420c0c300, 0x4c8a640, 0xc42000e008, 0x0, 0x0, 0x0, 0x0, 0xc42049fa88, 0x469ebf7, ...)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/cmd/gaia/cmd/gaiad/main.go:53 +0x86
github.com/cosmos/cosmos-sdk/server.ConstructAppExporter.func1(0x7ffeefbff2c5, 0x5, 0x4c815c0, 0xc420c0c300, 0x0, 0x0, 0x4618180, 0x49663c0, 0x0, 0x4ac36fe, ...)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/server/constructors.go:82 +0x14c
github.com/cosmos/cosmos-sdk/server.ExportCmd.func1(0xc420b71d40, 0xc420aad280, 0x0, 0x2, 0x0, 0x0)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/server/export.go:23 +0xf9
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).execute(0xc420b71d40, 0xc420aad220, 0x2, 0x2, 0xc420b71d40, 0xc420aad220)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:698 +0x46d
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc420b70900, 0x499b240, 0xc42049fe01, 0xc420aad180)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:783 +0x2e4
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).Execute(0xc420b70900, 0xc420aad180, 0xc42049fed8)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:736 +0x2b
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/libs/cli.Executor.Execute(0xc420b70900, 0x4c02548, 0x2, 0xc420b66840)
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/libs/cli/setup.go:89 +0x4e
main.main()
	/Users/redacted/.virtualgo/gaia/src/github.com/cosmos/cosmos-sdk/cmd/gaia/cmd/gaiad/main.go:38 +0x214

Steps to Reproduce

  • gaiad init
  • gaiad export

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@AdityaSripal
Copy link
Member

AdityaSripal commented Jul 26, 2018

I believe exporting any state with gaiad export will cause a panic on v0.23.0, though this has been fixed on develop

A quick fix is to add app.setCheckState(abci.Header{}) to baseapp's initFromStore method if you need to export state.

Solved in #1800

Edit: Misread. Currently can't export right after init.

@ValarDragon
Copy link
Contributor

I think you needed a state transition, or else it errored currently on develop.

@alexanderbez
Copy link
Contributor

Can we close this if fixed on develop?

@ValarDragon
Copy link
Contributor

cc @jlandrews, I don't think this is fixed.

@UnitylChaos
Copy link
Contributor

So I think the specific bug posted here has been fixed on develop but the fix wasn't merged into 0.23.0. I've just tested on develop though, and it looks like there is an error if you try to export right after an init. I get the following stack trace:

panic: Stored pool should not have been nil

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/x/stake/keeper.Keeper.GetPool(0x10704a0, 0xc420aaef70, 0xc420116230, 0x10704a0, 0xc420aaef50, 0xff9928, 0xc420116230, 0x4, 0x10781a0, 0xc420a719b0, ...)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/x/stake/keeper/keeper.go:84 +0x14c
github.com/cosmos/cosmos-sdk/x/stake.WriteGenesis(0x10781a0, 0xc420a719b0, 0xc4205874c0, 0x8, 0x10704a0, 0xc420aaef70, 0xc420116230, 0x10704a0, 0xc420aaef50, 0xff9928, ...)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/x/stake/genesis.go:62 +0xab
github.com/cosmos/cosmos-sdk/cmd/gaia/app.(*GaiaApp).ExportAppStateAndValidators(0xc420a265a0, 0xc420b111a0, 0x1081d60, 0xc420b081a8, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/app.go:204 +0x1d1
main.exportAppStateAndTMValidators(0x1078d60, 0xc420b111a0, 0x1081d60, 0xc420b081a8, 0x0, 0x0, 0x0, 0x0, 0xc420797a88, 0xa9d987, ...)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/cmd/gaiad/main.go:53 +0x86
github.com/cosmos/cosmos-sdk/server.ConstructAppExporter.func1(0xc4209bf160, 0x16, 0x1078d60, 0xc420b111a0, 0x0, 0x0, 0xa173a0, 0xd5ee80, 0x0, 0xebb08e, ...)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/server/constructors.go:82 +0x14c
github.com/cosmos/cosmos-sdk/server.ExportCmd.func1(0xc420a6a900, 0x1804a80, 0x0, 0x0, 0x0, 0x0)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/server/export.go:23 +0xf9
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).execute(0xc420a6a900, 0x1804a80, 0x0, 0x0, 0xc420a6a900, 0x1804a80)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:698 +0x46d
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc4200d1440, 0xd937a0, 0xc420797e01, 0xc420a60300)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:783 +0x2e4
github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra.(*Command).Execute(0xc4200d1440, 0xc420a60300, 0xc420797ed8)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/spf13/cobra/command.go:736 +0x2b
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/libs/cli.Executor.Execute(0xc4200d1440, 0xff9f10, 0x2, 0xc4209bf160)
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/libs/cli/setup.go:89 +0x4e
main.main()
	/home/jlandrews/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/cmd/gaiad/main.go:38 +0x214

Which I expect is happening because gaiad export attempts to load from the db, and the db has not been initialized with actual state yet. Not sure if this should be considered a bug or not. I suppose expected behavior could be that it basically just outputs the genesis file again, but to me dumping non existent state seems like something that should throw an error. Perhaps the real problem is that gaiad init doesn't actually initialize the state, it just creates a genesis file. (and possibly priv_validator.json / config.toml if they are missing)

@ValarDragon
Copy link
Contributor

ValarDragon commented Jul 27, 2018

Perhaps the real problem is that gaiad init doesn't actually initialize the state, it just creates a genesis file. (and possibly priv_validator.json / config.toml if they are missing)

Thats a good point. I'm not sure gaiad init should be initializing state however, since gaiad init --gen-tx is in the same command. Not sure what the answer to this is. If the answer is that we don't want to change gaiad init, then at the very least we should improve the error message of gaiad export to say something to the extent of "Error, state not initialized. Gaiad export can only be ran after a block has been created"

@AdityaSripal
Copy link
Member

@ValarDragon don't think that's true technically. Should be able to run as soon as the chain starts (i.e. before the first block)

@amrali
Copy link
Author

amrali commented Jul 27, 2018

I agree with @ValarDragon, if it purposefully panics now then this issue becomes only a UX issue where a better error message (possibly without the unnecessary stack trace) would be a good solution.

@ValarDragon
Copy link
Contributor

ValarDragon commented Jul 28, 2018

@ValarDragon don't think that's true technically. Should be able to run as soon as the chain starts (i.e. before the first block)

You're right, we can export before the first block, once we have a state. I guess we should change the message to "the chain must have started", or smth to that extent. Thanks for pointing that out.

Still not sure if gaiad init should initialize state as @jlandrews suggested. My primary concern is if you want to hand edit the genesis file after you create it via gaiad init, then you would have to call gaiad unsafe_reset_all which seems kinda weird, and will probably confuse more people in the future.

I'm not opposed to just special casing this situation. If there is no state, but the genesis file is created, return the current genesis file. (And display a warning as well) Its not like we're masking some bug with this special case (as not initializing state on gaiad init would be defined as intended behavior).

@jackzampolin
Copy link
Member

I think we should go ahead and special case this situation. Agree with @ValarDragon and @amrali here.

@mslipper mslipper mentioned this issue Aug 23, 2018
5 tasks
mslipper added a commit to mslipper/cosmos-sdk that referenced this issue Aug 24, 2018
fedekunze pushed a commit that referenced this issue Aug 24, 2018
chillyvee pushed a commit to chillyvee/cosmos-sdk that referenced this issue Mar 1, 2024
…osmos#1834)

Bumps [github.com/cosmos/cosmos-sdk](https://github.com/cosmos/cosmos-sdk) from 0.46.2 to 0.46.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/cosmos/cosmos-sdk/releases">github.com/cosmos/cosmos-sdk's releases</a>.</em></p>
<blockquote>
<h2>v0.46.3</h2>
<h1>Cosmos SDK v0.46.3 Release Notes</h1>
<p>This is a security release for the <a href="https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702">Dragonberry security advisory</a>.
Please upgrade ASAP.</p>
<p>Next to this, we have also included a few minor bugfixes.</p>
<p>Chains must add the following to their go.mod for the application:</p>
<pre lang="go"><code>replace github.com/confio/ics23/go =&gt; github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
</code></pre>
<p>Bumping the SDK version should be smooth, however, feel free to tag core devs to review your upgrading PR:</p>
<ul>
<li><strong>CET</strong>: <a href="https://github.com/tac0turtle"><code>@​tac0turtle</code></a>, <a href="https://github.com/okwme"><code>@​okwme</code></a>, <a href="https://github.com/AdityaSripal"><code>@​AdityaSripal</code></a>, <a href="https://github.com/colin-axner"><code>@​colin-axner</code></a>, <a href="https://github.com/julienrbrt"><code>@​julienrbrt</code></a></li>
<li><strong>EST</strong>: <a href="https://github.com/ebuchman"><code>@​ebuchman</code></a>, <a href="https://github.com/alexanderbez"><code>@​alexanderbez</code></a>, <a href="https://github.com/aaronc"><code>@​aaronc</code></a></li>
<li><strong>PST</strong>: <a href="https://github.com/jtremback"><code>@​jtremback</code></a>, <a href="https://github.com/nicolaslara"><code>@​nicolaslara</code></a>, <a href="https://github.com/czarcas7ic"><code>@​czarcas7ic</code></a>, <a href="https://github.com/p0mvn"><code>@​p0mvn</code></a></li>
<li><strong>CDT</strong>: <a href="https://github.com/ValarDragon"><code>@​ValarDragon</code></a>, <a href="https://github.com/zmanian"><code>@​zmanian</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/cosmos/cosmos-sdk/blob/main/CHANGELOG.md">github.com/cosmos/cosmos-sdk's changelog</a>.</em></p>
<blockquote>
<h2><a href="https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.3">v0.46.3</a> - 2022-10-20</h2>
<p>ATTENTION:</p>
<p>This is a security release for the <a href="https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702">Dragonberry security advisory</a>.</p>
<p>All users should upgrade immediately.</p>
<p>Users <em>must</em> add a replace directive in their go.mod for the new <code>ics23</code> package in the SDK:</p>
<pre lang="go"><code>replace github.com/confio/ics23/go =&gt; github.com/cosmos/cosmos-sdk/ics23/go v8.0.0
</code></pre>
<h3>Features</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13435">#13435</a> Extend error context when a simulation fails.</li>
<li>(grpc) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13485">#13485</a> Implement a new gRPC query, <code>/cosmos/base/node/v1beta1/config</code>, which provides operator configuration.</li>
<li>(cli) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13147">#13147</a> Add the <code>--append</code> flag to the <code>sign-batch</code> CLI cmd to combine the messages and sign those txs which are created with <code>--generate-only</code>.</li>
<li>(cli) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13454">#13454</a> <code>sign-batch</code> CLI can now read multiple transaction files.</li>
</ul>
<h3>Improvements</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13586">#13586</a> Bump Tendermint to <code>v0.34.22</code>.</li>
<li>(auth) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13460">#13460</a> The <code>q auth address-by-id</code> CLI command has been renamed to <code>q auth address-by-acc-num</code> to be more explicit. However, the old <code>address-by-id</code> version is still kept as an alias, for backwards compatibility.</li>
<li><a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13433">#13433</a> Remove dead code in cacheMergeIterator <code>Domain()</code>.</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li>Implement dragonberry security patch.
<ul>
<li>For applying the patch please refer to the <a href="https://github.com/cosmos/cosmos-sdk/blob/main/RELEASE_NOTES.md">RELEASE NOTES</a></li>
</ul>
</li>
<li>(store) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13459">#13459</a> Don't let state listener observe the uncommitted writes.</li>
<li><a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/12548">#12548</a> Prevent signing from wrong key while using multisig.</li>
</ul>
<h3>API Breaking Changes</h3>
<ul>
<li>(server) <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/pull/13485">#13485</a> The <code>Application</code> service now requires the <code>RegisterNodeService</code> method to be implemented.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/6d32debf1aca4b7f1ed1429d87be1d02c315f02d"><code>6d32deb</code></a> chore: bump tendermint to <code>0.34.22</code> (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13586">#13586</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/facd40d1423e29558c6891e70b66b451e99bae07"><code>facd40d</code></a> Merge pull request from GHSA-3qp7-gj37-g9rx</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/8667eba85db57555c0d7cc437566199e6b5e9549"><code>8667eba</code></a> refactor: Amend <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13497">#13497</a> (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13577">#13577</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/86e8bcb539218e6b2693780fc46d8d12ada8183f"><code>86e8bcb</code></a> refactor: Improve AllocateTokens (backport <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13524">#13524</a>) (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13526">#13526</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/2e3c37853d6be178d0c830128d0b4c161dcd3882"><code>2e3c378</code></a> chore: CHANGELOG update (backport <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13536">#13536</a>) (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13537">#13537</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/37912ec4a20d74b794b0cd828a10c898958b75e8"><code>37912ec</code></a> feat: gRPC query for operator and chain configuration (backport <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13485">#13485</a>) (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13497">#13497</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/f8778706afa70a3e576b408d63eac4892d8e4860"><code>f877870</code></a> feat: add MsgServiceRouter to Baseapp (and runtime's provideCodecs) (backport...</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/cb676e2647557543d658172d5a1be61cc40fa2a4"><code>cb676e2</code></a> fix: state listener could observe discarded writes (backport <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13459">#13459</a>) (<a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/13462">#13462</a>)</li>
<li><a href="https://github.com/cosmos/cosmos-sdk/commit/982b891921da32b7881a8d93942cf24ad4acc6b0"><code>982b891</code></a> refactor: Improve and clarify API around <code>AccountAddressById</code>  (backport <a href="https://github-redirect.dependabot.com/cosmos/cosmos-sdk/issues/134">#134</a>...</li>
<li>See full diff in <a href="https://github.com/cosmos/cosmos-sdk/compare/v0.46.2...v0.46.3">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/cosmos/cosmos-sdk&package-manager=go_modules&previous-version=0.46.2&new-version=0.46.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants