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

feat(nns): More secure random numbers. #1633

Merged
merged 10 commits into from
Sep 30, 2024
Merged

feat(nns): More secure random numbers. #1633

merged 10 commits into from
Sep 30, 2024

Conversation

max-dfinity
Copy link
Contributor

@max-dfinity max-dfinity commented Sep 23, 2024

In NNS Governance.

This is done by reseeding every hour. The seed is sourced from the raw_rand method of the management canister, and because of this, these seeds are "as secure as it gets". This is a compromise between speed and security that DFINITY's security team is ok with.

Currently, there is no need for secure RNs. However, that could come up in the future, and when it does, it would be too easy for us to overlook (without this change).

@max-dfinity max-dfinity changed the title Change signature of random methods to return errors if uninitialized RNG feat(nns): Use better RNG initialization Sep 24, 2024
@github-actions github-actions bot added the feat label Sep 24, 2024
@max-dfinity max-dfinity force-pushed the NNS1-3343 branch 2 times, most recently from f84b6ab to 9e21bb2 Compare September 24, 2024 22:22
@max-dfinity max-dfinity force-pushed the NNS1-3343 branch 2 times, most recently from 1ad6639 to f012787 Compare September 25, 2024 23:13
Copy link

@andrew-lee-work andrew-lee-work left a comment

Choose a reason for hiding this comment

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

Other than my other comment on the timer, LGTM.

I agree it's a good compromise between efficiency and secrecy of the seed to periodically generate a new seed for the CSPRNG.

I agree the deterministic fallback for swap time is good enough.

Also the fact that you only allow the proto to affect the seed on restoring and not when creating a new Governance is good. If you want to be extra careful in this regard you could also generate a warning if the proto unexpectedly has the seed set to Some().

rs/nns/governance/canister/canister.rs Show resolved Hide resolved
@daniel-wong-dfinity-org daniel-wong-dfinity-org changed the title feat(nns): Use better RNG initialization feat(nns): Secure random number generation. Sep 27, 2024
@daniel-wong-dfinity-org
Copy link
Contributor

daniel-wong-dfinity-org commented Sep 27, 2024

You maybe saw this already, but I changed title + description. Feel free to make further changes (or revert). I think my title is more informative (and more concise!), because "secure" is more precise than just "better". E.g. faster is a different way of being better, but faster is neither the intended, nor implemented.

Tangent

In general, we should refrain from describing changes as "better", "improve", etc, because that goes without saying. Instead, we should be specific. More concretely, we should instead answer, "In what regard is this better?".

@max-dfinity max-dfinity marked this pull request as ready for review September 27, 2024 15:31
@max-dfinity max-dfinity requested a review from a team as a code owner September 27, 2024 15:31
Copy link
Contributor

@daniel-wong-dfinity-org daniel-wong-dfinity-org left a comment

Choose a reason for hiding this comment

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

Result -> sad

rs/nns/governance/canister/canister.rs Show resolved Hide resolved
rs/nns/governance/canister/canister.rs Outdated Show resolved Hide resolved
rs/nns/governance/canister/canister.rs Outdated Show resolved Hide resolved
rs/nns/governance/canister/canister.rs Show resolved Hide resolved
rs/nns/governance/canister/canister.rs Show resolved Hide resolved
rs/nns/governance/src/governance.rs Outdated Show resolved Hide resolved
rs/nns/governance/src/governance.rs Show resolved Hide resolved
rs/nns/governance/src/heap_governance_data.rs Outdated Show resolved Hide resolved
rs/nns/governance/src/neuron_store.rs Outdated Show resolved Hide resolved
@daniel-wong-dfinity-org daniel-wong-dfinity-org changed the title feat(nns): Secure random number generation. feat(nns): More secure random numbers. Sep 27, 2024
rs/nns/governance/canister/canister.rs Outdated Show resolved Hide resolved
rs/nns/governance/canister/canister.rs Show resolved Hide resolved
rs/nns/governance/src/heap_governance_data.rs Outdated Show resolved Hide resolved
@max-dfinity max-dfinity added this pull request to the merge queue Sep 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 30, 2024
@max-dfinity max-dfinity added this pull request to the merge queue Sep 30, 2024
Merged via the queue into master with commit e9647a7 Sep 30, 2024
24 checks passed
@max-dfinity max-dfinity deleted the NNS1-3343 branch September 30, 2024 22:29
levifeldman pushed a commit to levifeldman/ic that referenced this pull request Oct 1, 2024
In NNS Governance.

This is done by reseeding every hour. The seed is sourced from the
raw_rand method of the management canister, and because of this, these
seeds are "as secure as it gets". This is a compromise between speed and
security that DFINITY's security team is ok with.

Currently, there is no need for secure RNs. However, that could come up
in the future, and when it does, it would be too easy for us to overlook
(without this change).

---------

Co-authored-by: IDX GitHub Automation <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants