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

test(bug): In TestKeyManagement, test GetByAddress after replacing a key with the same name #2684

Conversation

jefft0
Copy link
Contributor

@jefft0 jefft0 commented Aug 13, 2024

This PR demonstrates a bug. TestKeyManagement creates a key named "n2" with Info "i2". This PR adds GetByAddress and confirms that the public key in the retrieved Info matches the original public key. So good so far. Then the test calls CreateAccount to replace the entry for the same name with a new key (address). It calls GetByAddress with the original address, which successfully returns Info.

Expected: The public key in the Info should correspond to the address that it is fetched by.
Actual: The test fails because the public key doesn't match. (The "lookup by address" entry maps to the name "n2" but now that name entry has new Info.

To run the test:

cd gno/tm2/pkg/crypto/keys
go test .

Discussion: CreateAccount is allowed to replace the entry for a name with new Info (new address), but it leaves the existing "lookup by address" entry untouched. This creates the possibility of GetByAddress returning a public key which doesn't correspond to that address. This can cause problems with attempting to use the key, expecting it to match the address. A possible solution: When replacing a name entry with new Info, remove the "lookup by address" entry for the existing address. GetByAddress with the old address should fail.

…key with the same name. See the PR.

Signed-off-by: Jeff Thompson <jeff@thefirst.org>
@jefft0 jefft0 requested review from jaekwon, moul and a team as code owners August 13, 2024 12:16
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Aug 13, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.15%. Comparing base (bbcb2f6) to head (eb9ed77).
Report is 121 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2684      +/-   ##
==========================================
+ Coverage   60.11%   60.15%   +0.03%     
==========================================
  Files         560      561       +1     
  Lines       74918    74999      +81     
==========================================
+ Hits        45039    45114      +75     
- Misses      26504    26507       +3     
- Partials     3375     3378       +3     
Flag Coverage Δ
contribs/gnodev 60.58% <ø> (-0.82%) ⬇️
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 64.75% <ø> (+0.57%) ⬆️
gnovm 64.13% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jefft0
Copy link
Contributor Author

jefft0 commented Aug 13, 2024

A possible fix for the bug demonstrated in this PR is #2685, so I set this PR to Draft. If that PR is merged, then we can close this PR.

thehowl pushed a commit that referenced this pull request Oct 22, 2024
…remove the lookup by the old address (#2685)

This PR fixes the bug demonstrated in
#2684 :
* In `dbKeybase.writeInfo`, add an `error` return and propagate this to
all callers (`writeLocalKey`, etc.) . We need `writeInfo` to do some
database integrity checks, so it needs to be able to return an error.
* Update `dbKeybase.writeInfo` as suggested in
[#2684](#2684) . If an existing name
entry is being replaced with new `Info`, then remove the "lookup by
address" entry for the existing address.
* In `TestKeyManagement`, add a test similar to
[#2684](#2684) , except that after
using `CreateAccount` with the same name, expect `GetByAddress` to fail
for the obsolete address and its (non-existing) public key. (This test
passes.)

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <jeff@thefirst.org>
@thehowl thehowl closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants