1010using System . Runtime . Intrinsics ;
1111using System . Runtime . Intrinsics . Arm ;
1212using System . Runtime . Intrinsics . X86 ;
13+ using System . Security . Cryptography ;
1314
1415[ assembly: InternalsVisibleTo ( "Nethermind.Int256.Tests" ) ]
1516
@@ -22,7 +23,13 @@ namespace Nethermind.Int256;
2223 // Ensure that hashes are different for every run of the node and every node, so if are any hash collisions on
2324 // one node they will not be the same on another node or across a restart so hash collision cannot be used to degrade
2425 // the performance of the network as a whole.
25- private static readonly uint s_instanceRandom = ( uint ) System . Security . Cryptography . RandomNumberGenerator . GetInt32 ( int . MinValue , int . MaxValue ) ;
26+ // Constant by default for zkVM-compatibility -- subject to change in the near feature
27+ private static readonly uint _hashSeed = UseHashCodeRandomizer
28+ ? ( uint ) RandomNumberGenerator . GetInt32 ( int . MinValue , int . MaxValue )
29+ : 2098026241U ; // just a random prime number
30+
31+ [ FeatureSwitchDefinition ( "Nethermind.Int256.UseHashCodeRandomizer" ) ]
32+ public static bool UseHashCodeRandomizer => AppContext . TryGetSwitch ( "Nethermind.Int256.UseHashCodeRandomizer" , out var useHashCodeRandomizer ) && useHashCodeRandomizer ;
2633
2734 public static readonly UInt256 Zero = 0ul ;
2835 public static readonly UInt256 One = 1ul ;
@@ -1396,7 +1403,7 @@ public override int GetHashCode()
13961403 // Very fast hardware accelerated non-cryptographic hash function
13971404
13981405 // Start with instance random, length and first ulong as seed
1399- uint hash = BitOperations . Crc32C ( s_instanceRandom , u0 ) ;
1406+ uint hash = BitOperations . Crc32C ( _hashSeed , u0 ) ;
14001407
14011408 // Crc32C is 3 cycle latency, 1 cycle throughput
14021409 // So we use same initial 3 times to not create a dependency chain
0 commit comments