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

No longer ever reuse keypool indexes #10795

Merged
merged 1 commit into from
Jul 18, 2017

Conversation

TheBlueMatt
Copy link
Contributor

This fixes an issue where you could reserve a keypool entry, then
top up the keypool, writing out a new key at the given index, then
return they key from the pool. This isnt likely to cause issues,
but given there is no reason to ever re-use keypool indexes
(they're 64 bits...), best to avoid it alltogether.

Builds on #10235, should probably get a 15 tag.

@laanwj laanwj added this to the 0.15.0 milestone Jul 11, 2017
@laanwj laanwj added the Wallet label Jul 11, 2017
@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 1e42dd0 to 7e11ab8 Compare July 11, 2017 22:24
@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 7e11ab8 to 501dd26 Compare July 11, 2017 22:30
@bitcoin bitcoin deleted a comment Jul 11, 2017
@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 501dd26 to 1c01ea6 Compare July 12, 2017 15:49
@morcos
Copy link
Member

morcos commented Jul 12, 2017

utACK 1c01ea6

bugfix needed for 0.15

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

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

utACK 1c01ea6

nEnd = std::max(nEnd, *(setExternalKeyPool.rbegin()) + 1);
}
int64_t index = ++m_max_keypool_index;
assert(index >= 0); // How in the hell did you use so many keys?
Copy link
Member

Choose a reason for hiding this comment

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

Signed overflow is undefined behaviour, so the compiler is allowed to optimize this assert out (it can assume overflow never happens).

Copy link
Member

Choose a reason for hiding this comment

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

heh, i almost commented that it would be clearer to check against max

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, but in practice it doesnt, plus its just an assert, so whatever :).

Copy link
Contributor

Choose a reason for hiding this comment

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

Code like this makes me go "wtf were the authors of this smoking": asserts like this are usually optimized out, so the code looks like it's saying that the author thought the signed overflow was kosher and that they thought it could happen here.

Copy link
Member

@laanwj laanwj Jul 17, 2017

Choose a reason for hiding this comment

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

Would be better (non-UB, but also more clear to read) to check against std::numeric_limits<int64_t>::max() before the increase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sipa
Copy link
Member

sipa commented Jul 16, 2017

Needs rebase.

@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 1c01ea6 to 44d0996 Compare July 16, 2017 22:51
@TheBlueMatt
Copy link
Contributor Author

Rebased.

@laanwj
Copy link
Member

laanwj commented Jul 17, 2017

LGTM, what a foresight Satoshi had to use 64 bit numbers for keypool indexes in walletdb.

@morcos
Copy link
Member

morcos commented Jul 17, 2017

re-utACK 44d0996

@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 44d0996 to 44af47a Compare July 17, 2017 15:01
@gmaxwell
Copy link
Contributor

@TheBlueMatt plz2rebase

This fixes an issue where you could reserve a keypool entry, then
top up the keypool, writing out a new key at the given index, then
return they key from the pool. This isnt likely to cause issues,
but given there is no reason to ever re-use keypool indexes
(they're 64 bits...), best to avoid it alltogether.
@TheBlueMatt
Copy link
Contributor Author

Rebased.

@TheBlueMatt TheBlueMatt force-pushed the 2017-07-wallet-keypool-overwrite branch from 44af47a to 1fc8c3d Compare July 17, 2017 16:12
@morcos
Copy link
Member

morcos commented Jul 17, 2017

re-re-utACK 1fc8c3d
(one more and I think git will do it for me)

@laanwj laanwj merged commit 1fc8c3d into bitcoin:master Jul 18, 2017
laanwj added a commit that referenced this pull request Jul 18, 2017
1fc8c3d No longer ever reuse keypool indexes (Matt Corallo)

Pull request description:

  This fixes an issue where you could reserve a keypool entry, then
  top up the keypool, writing out a new key at the given index, then
  return they key from the pool. This isnt likely to cause issues,
  but given there is no reason to ever re-use keypool indexes
  (they're 64 bits...), best to avoid it alltogether.

  Builds on #10235, should probably get a 15 tag.

Tree-SHA512: c13a18a90f1076fb74307f2d64e9d80149811524c6bda259698ff2c65adaf8c6c3f2a3a07a5f4bf03251bc942ba8f5fd33a4427aa4256748c40b062991682caf
@jonasschnelli
Copy link
Contributor

post merge ACK

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 16, 2019
1fc8c3d No longer ever reuse keypool indexes (Matt Corallo)

Pull request description:

  This fixes an issue where you could reserve a keypool entry, then
  top up the keypool, writing out a new key at the given index, then
  return they key from the pool. This isnt likely to cause issues,
  but given there is no reason to ever re-use keypool indexes
  (they're 64 bits...), best to avoid it alltogether.

  Builds on bitcoin#10235, should probably get a 15 tag.

Tree-SHA512: c13a18a90f1076fb74307f2d64e9d80149811524c6bda259698ff2c65adaf8c6c3f2a3a07a5f4bf03251bc942ba8f5fd33a4427aa4256748c40b062991682caf
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2019
1fc8c3d No longer ever reuse keypool indexes (Matt Corallo)

Pull request description:

  This fixes an issue where you could reserve a keypool entry, then
  top up the keypool, writing out a new key at the given index, then
  return they key from the pool. This isnt likely to cause issues,
  but given there is no reason to ever re-use keypool indexes
  (they're 64 bits...), best to avoid it alltogether.

  Builds on bitcoin#10235, should probably get a 15 tag.

Tree-SHA512: c13a18a90f1076fb74307f2d64e9d80149811524c6bda259698ff2c65adaf8c6c3f2a3a07a5f4bf03251bc942ba8f5fd33a4427aa4256748c40b062991682caf
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
1fc8c3d No longer ever reuse keypool indexes (Matt Corallo)

Pull request description:

  This fixes an issue where you could reserve a keypool entry, then
  top up the keypool, writing out a new key at the given index, then
  return they key from the pool. This isnt likely to cause issues,
  but given there is no reason to ever re-use keypool indexes
  (they're 64 bits...), best to avoid it alltogether.

  Builds on bitcoin#10235, should probably get a 15 tag.

Tree-SHA512: c13a18a90f1076fb74307f2d64e9d80149811524c6bda259698ff2c65adaf8c6c3f2a3a07a5f4bf03251bc942ba8f5fd33a4427aa4256748c40b062991682caf
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants