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: make makeNonce return unique random values #546

Merged
merged 6 commits into from Mar 25, 2022

Conversation

ericswanson-dfinity
Copy link
Member

@ericswanson-dfinity ericswanson-dfinity commented Mar 23, 2022

Description

The makeNonce method ended up returning the same value: 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

There were a couple problems:

  • DateTime.now() * 100,000 didn't extend any values into the high 64 bits
  • view.setBigUint64(1, value) sets 8 bytes starting at byte offset 1, not the address of the second biguint64

The end result was that only the first byte of the nonce would have a nonzero value.

This change puts the current time in the high 64 bits (the first several bytes are still zero), and fills the low 64 bits with random data.

Fixes https://dfinity.atlassian.net/browse/SDK-396

How Has This Been Tested?

The first commit in this branch added a unit test, the failure of which demonstrates that the nonce values were not unique.

Checklist:

  • My changes follow the guidelines in CONTRIBUTING.md.
  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • There were no required changes to the documentation.

@ericswanson-dfinity ericswanson-dfinity marked this pull request as ready for review March 23, 2022 21:10
@krpeacock krpeacock merged commit 1717113 into main Mar 25, 2022
@krpeacock krpeacock deleted the ericswanson/makenonce-unique-test branch March 25, 2022 22:47
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.

None yet

2 participants