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

Uninitialized accounts are unmarshalled with invalid data #661

Open
zivkovicmilos opened this issue Mar 28, 2023 · 5 comments
Open

Uninitialized accounts are unmarshalled with invalid data #661

zivkovicmilos opened this issue Mar 28, 2023 · 5 comments
Assignees
Labels
🐞 bug Something isn't working 🗺️good first issue🗺️ Ideal for newcomer contributors help wanted Want to contribute? We recommend these issues. 📦 ⛰️ gno.land Issues or PRs gno.land package related

Comments

@zivkovicmilos
Copy link
Member

Uninitialized accounts are returned with invalid data

Description

Executing a query to auth/accounts/<address> for a previously unseen address returns a nil response to an ABCI query result. This can lead to an invalid account (zero address) being returned (when unmarshalling this ABCI response on the client).

Your environment

Steps to reproduce

  • Generate an address that has not been used with the gno chain before (ex. with gnokey generate / add)
  • Query it using the path auth/accounts/<address> from a client (ex. client.ABCIQuery)
  • When unmarshalling the results into a gnoland.GnoAccount, the data will not match what was queries (address is zero address)

Expected behaviour

The account data should be returned (and filled correctly) even if the account is not found in the blockchain storage

Actual behaviour

If the account is not found, nil is returned, leading to an invalid unmarshal operation on ABCI clients.

Logs

./build/gnokey query --remote localhost:26657 --height 1 auth/accounts/g1zhrdmurv3yqwpct7s09rgk0l3yj6kgtyf7hd2f
height: 0
data: null

Proposed solution

Account fetches should never return nil, but rather initialize the account and return it.

@zivkovicmilos zivkovicmilos self-assigned this Mar 28, 2023
@zivkovicmilos
Copy link
Member Author

cc @moul

Initializing and saving unknown accounts on query requests can have real side-effects on storage, so I suggest we discuss how we want to go about solving a problem like this

@zivkovicmilos zivkovicmilos changed the title Uninitialized accounts are returned with invalid data Uninitialized accounts are unmarshalled with invalid data Mar 28, 2023
@moul
Copy link
Member

moul commented Mar 29, 2023

Hey, thank you.

@zivkovicmilos: what do you suggest?

Anyone: any feedback on how other chains handle this is a manner you prefer?

@zivkovicmilos
Copy link
Member Author

Hey, thank you.

@zivkovicmilos: what do you suggest?

Anyone: any feedback on how other chains handle this is a manner you prefer?

Not exactly sure what should be the appropriate fix that doesn't have any unwanted side effects.

Ethereum handles these situations (querying of previously untouched accounts) in the following manner:

  • accounts are not initialized in the state tree until they need to be (they are part of a state transition)
  • when a node does not find the account in its storage (it's "unknown"), it constructs a response for the user with default parameters (non-empty ones, so it fills out the account object as if it were fetched from storage, but note that it doesn't initialize the account in the storage itself)

I honestly see no problem in doing the same on our Tendermint node, the only thing I'm worried about is the Account Number param for the BaseAccount. If I understood correctly, this is dependent on state, meaning the account needs to be initialized already (number secured, so no two accounts have the same one). Is this correct?

@tbruyelle
Copy link
Contributor

tbruyelle commented Mar 29, 2023

I honestly see no problem in doing the same on our Tendermint node, the only thing I'm worried about is the Account Number param for the BaseAccount. If I understood correctly, this is dependent on state, meaning the account needs to be initialized already (number secured, so no two accounts have the same one). Is this correct?

I like the idea of returning a pre-initialized account if the passed address doesn't exist, unfortunately as you mentioned it's not possible due to the account number, which is a global counter incremented each time a new account is created.

The other way of dealing with non-existent account would be to return an error instead of nil, but not sure I prefer that...

@ajnavarro ajnavarro added 🐞 bug Something isn't working 📦 ⛰️ gno.land Issues or PRs gno.land package related and removed bug labels May 15, 2023
@moul moul moved this to 🏆 Needed for Launch in 🚀 The Launch [DEPRECATED] Sep 5, 2023
@moul moul added this to the 🚀 main.gno.land milestone Sep 6, 2023
@Kouteki Kouteki added help wanted Want to contribute? We recommend these issues. and removed help wanted labels Oct 2, 2024
@moul
Copy link
Member

moul commented Oct 15, 2024

I suggest we return an AccountNotFound error or panic.

This is a straightforward issue in tm2/pkg/sdk/auth if someone wants to give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🗺️good first issue🗺️ Ideal for newcomer contributors help wanted Want to contribute? We recommend these issues. 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: Backlog
Development

No branches or pull requests

5 participants