-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Insecure Random Number Generation #3431
Comments
|
Agreed |
The random data should be hashed Example: static ulong GetNonce()
{
Span<byte> seed = stackalloc byte[8];
Span<byte> source = stackalloc byte[8];
RandomNumberGenerator.Fill(seed);
RandomNumberGenerator.Fill(source);
var hash = HMACSHA384.HashData(seed, source);
var start = Math.Abs(new Random(Random.Shared.Next()).Next(buffer.Length - 8));
return BinaryPrimitives.ReadUInt64LittleEndian(hash[start..]);
} Outputs
|
Closed by #3432 |
Security Issue: Insecure Random Number Generation in NEO Blockchain
Description
neo/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs
Lines 169 to 175 in f307a31
The issue lies in the use of the
Random
class for generating random numbers, specifically the instantiationRandom _random = new();
. It is well-known that theRandom
constructor uses a default seed value. Referencing dotnet's manual here. Usually the seed is derived from system clock and some other factors like another PRNG. And the timestamp of the consensus is exposed in the block header which makes it more easier for guessing the seed.Impact
This predictability poses a significant security risk. By analyzing a large set of published block data, there exists possibility to infer the random seed sequence of a consensus node. With this information, one could predict some blocks' nonce values of future blocks. Therefore, one can manipulate a transactions's nonce so that the value got from
System.Runtime.GetRandom
is preferable.The block nonce are the crucial random source for various on-chain applications. Applications relying on these random source include:
Suggested Fix
To mitigate this issue, I recommend using a cryptographically secure random number generator, such as RNGCryptoServiceProvider in C#. This will ensure that the random numbers used in block generation are not predictable and significantly enhance the security of the blockchain.
Possible Example:
Conclusion
The current method of random number generation in the NEO blockchain is insecure and can be exploited to predict block nonce values. This poses a serious risk to the integrity of on-chain applications. Implementing a cryptographically secure random number generator will address this vulnerability.
The text was updated successfully, but these errors were encountered: