Skip to content

Commit bd1247e

Browse files
committed
Recreates tests with different entropy values
1 parent 856eb2e commit bd1247e

File tree

3 files changed

+494
-471
lines changed

3 files changed

+494
-471
lines changed

shuffle/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ This section presents two definitions, a recursive one that uses an integer sequ
55

66
The implementation of Eq 329 is not generally used in the Gray Paper, and so we present test vectors only for the version of Eq 331. However, the present script creates these test cases with recourse to the Eq 329 implementation, to reproduce exactly the definition of the Gray Paper.
77

8+
Note: All gray paper references in this document are to version 0.4.3, October 21st 2024.
9+
810
## Notes about test parameters
911

1012
In every case, the output must be a permutation of the input sequence, and this is checked by the generating script.
1113
In the GP, at the moment, this function is used only to shuffle sequences of validators or cores, both of which are identified by integers. For that reason, all test cases use integers as the input type. All the input elements are distinct to ensure the final positions of each element are unambiguously determined.
1214

13-
All test cases use the same entropy, which is a 32-byte sequence with values from 0 to 31.
14-
1515
All the inputs to each test case are integer sequences, ranging from 0 to n-1, where n is the length. The test cases are described only by the entropy and the length of the input, and so the actual input sequence has to be recreated when using these test cases.
1616

1717
## Test vectors

shuffle/main.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,44 @@ def compute_shuffle_eq329(s, r):
2626
def number_vector(n):
2727
return [x for x in range(n)]
2828

29-
def default_seed():
30-
return [i for i in range(32)]
29+
def uniform_seed(n):
30+
return [n] * 32
3131

32-
def inputs_Eq331():
33-
seed = default_seed()
32+
def linear_seed():
33+
return [i for i in range(32)]
3434

35-
yield(number_vector(0), seed)
36-
yield(number_vector(8), seed)
37-
yield(number_vector(16), seed)
38-
yield(number_vector(20), seed)
35+
def varied_seed(n):
36+
# large 32 bit prime
37+
large_prime = 2147483647
38+
result = []
39+
next = n % large_prime
40+
41+
# next is always a 32-bit prime, so it fits in 4 bytes.
42+
# this loop generates a cycle of modular exponents of a generator.
43+
# if this generator is unknown, this cycle is in practice unpredictable,
44+
# so this should generate a sequence that looks a bit like random
45+
# and should be enough for simple tests.
46+
for i in range(8):
47+
result = result + list(to_le_bytes(next, 4))
48+
next = next * n % large_prime
49+
50+
return result
3951

40-
yield(number_vector(50), seed)
41-
yield(number_vector(100), seed)
42-
yield(number_vector(200), seed)
43-
yield(number_vector(341), seed)
52+
def inputs_Eq331():
53+
zero_seed = uniform_seed(0)
54+
ff_seed = uniform_seed(255)
55+
simple_seed = linear_seed()
56+
irregular_seed = varied_seed(1_000_000_000_000)
57+
58+
yield(number_vector(0), zero_seed)
59+
yield(number_vector(8), ff_seed)
60+
yield(number_vector(16), simple_seed)
61+
yield(number_vector(20), irregular_seed)
62+
63+
yield(number_vector(50), zero_seed)
64+
yield(number_vector(100), ff_seed)
65+
yield(number_vector(200), simple_seed)
66+
yield(number_vector(341), irregular_seed)
4467

4568

4669
def to_le_bytes(n, k):

0 commit comments

Comments
 (0)