Skip to content

signer/core: fix reference issue in key derivation #19827

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

Merged
merged 2 commits into from
Jul 18, 2019

Conversation

gballet
Copy link
Member

@gballet gballet commented Jul 11, 2019

Currently in clé clef, the derivation process reuses the same derivation path array as input to the Derive function. That Derive function creates an account and keeps a pointer to the derivation path for other purposes.

Since the derivation path gets updated each time Derive is called, all accounts end up having the rug pulled from under their feet: the derivation path they point to will be that of the first non-valid account.

So this PR simply makes sure that one derivation path is allocated each time.

@gballet gballet requested a review from holiman July 11, 2019 11:05
@gballet gballet added this to the 1.9.1 milestone Jul 11, 2019
@karalabe
Copy link
Member

This seems like a bug in a specific derivation method. It should definitely not keep a pointer to the path, rather make a copy if it needs it. Where does it originate from though, Ledger and Trezor only use it for a request, but don't mutate it as far as I see it.

@karalabe
Copy link
Member

Ah, indeed it does keep a reference. Please make a copy here: https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/wallet.go#L482.

@gballet gballet force-pushed the clef-sign-hw-key-derivation branch from 37c600b to 5f46edc Compare July 17, 2019 12:21
@gballet gballet requested a review from karalabe as a code owner July 17, 2019 12:21
@@ -479,7 +479,7 @@ func (w *wallet) Derive(path accounts.DerivationPath, pin bool) (accounts.Accoun

if _, ok := w.paths[address]; !ok {
w.accounts = append(w.accounts, account)
w.paths[address] = path
copy(w.paths[address], path)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make a new copy. It retrieves w.paths[address], which will be an empty slice (nil) and then copy into it, limited to the length of the smallest operand (i.e. nil, length of 0`) and return. I.e. this is a noop.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I just saw debugging the other PR 😞

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we can make a Copy method for accounts.DerivationPath, might come in handy long term for Clef too.

@karalabe karalabe merged commit 9466b9e into ethereum:master Jul 18, 2019
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Jan 2, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 3, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 4, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 6, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 7, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 7, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 7, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 9, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 10, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 10, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 10, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 10, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 14, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 16, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 17, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 22, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 22, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 23, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 24, 2025
* signer/core: fix reference issue in key derivation

* Review feedback
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 this pull request may close these issues.

2 participants