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

fix: In dbKeybase.writeInfo, if replacing a name entry, remove the lookup by the old address #2685

Merged

Conversation

jefft0
Copy link
Contributor

@jefft0 jefft0 commented Aug 13, 2024

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 . 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 , 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.)
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

…okup by the old address. See the PR.

Signed-off-by: Jeff Thompson <[email protected]>
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 53.33333% with 14 lines in your changes missing coverage. Please review.

Project coverage is 60.21%. Comparing base (651f5aa) to head (72a4b46).
Report is 96 commits behind head on master.

Files with missing lines Patch % Lines
tm2/pkg/crypto/keys/keybase.go 53.33% 10 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2685      +/-   ##
==========================================
- Coverage   60.22%   60.21%   -0.01%     
==========================================
  Files         562      562              
  Lines       75038    75048      +10     
==========================================
- Hits        45188    45187       -1     
- Misses      26476    26482       +6     
- Partials     3374     3379       +5     
Flag Coverage Δ
contribs/gnodev 61.40% <ø> (ø)
contribs/gnofaucet 15.31% <ø> (ø)
gno.land 64.57% <ø> (ø)
gnovm 64.33% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.04% <53.33%> (+0.06%) ⬆️

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.

@Kouteki Kouteki added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 3, 2024
Copy link
Member

@notJoon notJoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The major changes made in the writeMultisigKey and writeInfo functions are well covered in the tests. I think this PR can move on to the next step 👍

remove review/triage-pending flag

@notJoon notJoon removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 22, 2024
@thehowl thehowl merged commit 4b68712 into gnolang:master Oct 22, 2024
119 checks passed
zivkovicmilos pushed a commit that referenced this pull request Dec 6, 2024
The `Keybase` interface was written with the assumption of a one-to-one
correspondence between a key's name and address. But this needs to be
enforced by the code. PR #2685
updated `writeInfo` for the case of inserting a new key (address) with
the same name as an existing key with a different address. In this case,
`writeInfo` uses the name to look up the existing address and deletes
the address entry.

This PR does the same for the other case: Inserting a key with the same
address as an existing key, but a new name. In this case, `writeInfo`
uses the address to look up the existing key's name, and deletes the
name entry.

This is not a breaking change because none of the production code
expects to add a key a second time with the same address but a different
name. We update the `Keybase` doc comments to this effect. However, some
of the tests in keybase_test.go make this assumption, so this PR fixes
them:

* `TestSignVerify` creates a key with name n2 and exports its public
key. It wants to re-import the public key with name n3 and get the
public key to check that it is the same public key as n2. We change this
test to re-import the public key into a fresh in-memory key store.
* `TestExportImportPubKey` creates a key with name "john", exports its
public key, then re-imports it with the new name "john-pubkey-only" (but
the same address). The current test checks that the key can still be
fetched under the old name "john". But this breaks the one-to-one
correspondence of key name and address. So the test is changed to
confirm that the key with the old name is replaced by the new name.

<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
- [ ] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <[email protected]>
omarsy pushed a commit to TERITORI/gno that referenced this pull request Dec 7, 2024
The `Keybase` interface was written with the assumption of a one-to-one
correspondence between a key's name and address. But this needs to be
enforced by the code. PR gnolang#2685
updated `writeInfo` for the case of inserting a new key (address) with
the same name as an existing key with a different address. In this case,
`writeInfo` uses the name to look up the existing address and deletes
the address entry.

This PR does the same for the other case: Inserting a key with the same
address as an existing key, but a new name. In this case, `writeInfo`
uses the address to look up the existing key's name, and deletes the
name entry.

This is not a breaking change because none of the production code
expects to add a key a second time with the same address but a different
name. We update the `Keybase` doc comments to this effect. However, some
of the tests in keybase_test.go make this assumption, so this PR fixes
them:

* `TestSignVerify` creates a key with name n2 and exports its public
key. It wants to re-import the public key with name n3 and get the
public key to check that it is the same public key as n2. We change this
test to re-import the public key into a fresh in-memory key store.
* `TestExportImportPubKey` creates a key with name "john", exports its
public key, then re-imports it with the new name "john-pubkey-only" (but
the same address). The current test checks that the key can still be
fetched under the old name "john". But this breaks the one-to-one
correspondence of key name and address. So the test is changed to
confirm that the key with the old name is replaced by the new name.

<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
- [ ] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <[email protected]>
Villaquiranm pushed a commit to Villaquiranm/gno that referenced this pull request Dec 9, 2024
The `Keybase` interface was written with the assumption of a one-to-one
correspondence between a key's name and address. But this needs to be
enforced by the code. PR gnolang#2685
updated `writeInfo` for the case of inserting a new key (address) with
the same name as an existing key with a different address. In this case,
`writeInfo` uses the name to look up the existing address and deletes
the address entry.

This PR does the same for the other case: Inserting a key with the same
address as an existing key, but a new name. In this case, `writeInfo`
uses the address to look up the existing key's name, and deletes the
name entry.

This is not a breaking change because none of the production code
expects to add a key a second time with the same address but a different
name. We update the `Keybase` doc comments to this effect. However, some
of the tests in keybase_test.go make this assumption, so this PR fixes
them:

* `TestSignVerify` creates a key with name n2 and exports its public
key. It wants to re-import the public key with name n3 and get the
public key to check that it is the same public key as n2. We change this
test to re-import the public key into a fresh in-memory key store.
* `TestExportImportPubKey` creates a key with name "john", exports its
public key, then re-imports it with the new name "john-pubkey-only" (but
the same address). The current test checks that the key can still be
fetched under the old name "john". But this breaks the one-to-one
correspondence of key name and address. So the test is changed to
confirm that the key with the old name is replaced by the new name.

<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
- [ ] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <[email protected]>
r3v4s pushed a commit to gnoswap-labs/gno that referenced this pull request Dec 10, 2024
The `Keybase` interface was written with the assumption of a one-to-one
correspondence between a key's name and address. But this needs to be
enforced by the code. PR gnolang#2685
updated `writeInfo` for the case of inserting a new key (address) with
the same name as an existing key with a different address. In this case,
`writeInfo` uses the name to look up the existing address and deletes
the address entry.

This PR does the same for the other case: Inserting a key with the same
address as an existing key, but a new name. In this case, `writeInfo`
uses the address to look up the existing key's name, and deletes the
name entry.

This is not a breaking change because none of the production code
expects to add a key a second time with the same address but a different
name. We update the `Keybase` doc comments to this effect. However, some
of the tests in keybase_test.go make this assumption, so this PR fixes
them:

* `TestSignVerify` creates a key with name n2 and exports its public
key. It wants to re-import the public key with name n3 and get the
public key to check that it is the same public key as n2. We change this
test to re-import the public key into a fresh in-memory key store.
* `TestExportImportPubKey` creates a key with name "john", exports its
public key, then re-imports it with the new name "john-pubkey-only" (but
the same address). The current test checks that the key can still be
fetched under the old name "john". But this breaks the one-to-one
correspondence of key name and address. So the test is changed to
confirm that the key with the old name is replaced by the new name.

<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
- [ ] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <[email protected]>
albttx pushed a commit that referenced this pull request Jan 10, 2025
The `Keybase` interface was written with the assumption of a one-to-one
correspondence between a key's name and address. But this needs to be
enforced by the code. PR #2685
updated `writeInfo` for the case of inserting a new key (address) with
the same name as an existing key with a different address. In this case,
`writeInfo` uses the name to look up the existing address and deletes
the address entry.

This PR does the same for the other case: Inserting a key with the same
address as an existing key, but a new name. In this case, `writeInfo`
uses the address to look up the existing key's name, and deletes the
name entry.

This is not a breaking change because none of the production code
expects to add a key a second time with the same address but a different
name. We update the `Keybase` doc comments to this effect. However, some
of the tests in keybase_test.go make this assumption, so this PR fixes
them:

* `TestSignVerify` creates a key with name n2 and exports its public
key. It wants to re-import the public key with name n3 and get the
public key to check that it is the same public key as n2. We change this
test to re-import the public key into a fresh in-memory key store.
* `TestExportImportPubKey` creates a key with name "john", exports its
public key, then re-imports it with the new name "john-pubkey-only" (but
the same address). The current test checks that the key can still be
fetched under the old name "john". But this breaks the one-to-one
correspondence of key name and address. So the test is changed to
confirm that the key with the old name is replaced by the new name.

<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
- [ ] Provided any useful hints for running manual tests
</details>

Signed-off-by: Jeff Thompson <[email protected]>
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.

4 participants