@@ -33,8 +33,8 @@ func TestDeriveCoefficients(t *testing.T) {
3333 rowRoot := sha256 .Sum256 ([]byte ("test root" ))
3434
3535 // Derive coefficients
36- coeffs1 := deriveCoefficients (rowRoot , config .RowSize )
37- coeffs2 := deriveCoefficients (rowRoot , config .RowSize )
36+ coeffs1 := deriveCoefficients (rowRoot , config .K , config . N , config . RowSize )
37+ coeffs2 := deriveCoefficients (rowRoot , config .K , config . N , config . RowSize )
3838
3939 // Test determinism
4040 if len (coeffs1 ) != len (coeffs2 ) {
@@ -55,7 +55,7 @@ func TestDeriveCoefficients(t *testing.T) {
5555
5656 // Test that different roots produce different coefficients
5757 differentRoot := sha256 .Sum256 ([]byte ("different root" ))
58- coeffs3 := deriveCoefficients (differentRoot , config .RowSize )
58+ coeffs3 := deriveCoefficients (differentRoot , config .K , config . N , config . RowSize )
5959
6060 allSame := true
6161 for i := range coeffs1 {
@@ -98,7 +98,7 @@ func TestComputeRLC(t *testing.T) {
9898
9999 // Derive coefficients
100100 rowRoot := sha256 .Sum256 ([]byte ("test" ))
101- coeffs := deriveCoefficients (rowRoot , config .RowSize )
101+ coeffs := deriveCoefficients (rowRoot , config .K , config . N , config . RowSize )
102102
103103 // Compute RLC
104104 rlc1 := computeRLC (row , coeffs )
@@ -190,7 +190,7 @@ func TestRLCLinearity(t *testing.T) {
190190
191191 // Derive coefficients
192192 rowRoot := sha256 .Sum256 ([]byte ("test" ))
193- coeffs := deriveCoefficients (rowRoot , config .RowSize )
193+ coeffs := deriveCoefficients (rowRoot , config .K , config . N , config . RowSize )
194194
195195 // Compute RLCs
196196 rlcA := computeRLC (rowA , coeffs )
@@ -247,45 +247,50 @@ func TestCommitmentDeterminism(t *testing.T) {
247247}
248248
249249func TestCoefficientsConsistency (t * testing.T ) {
250- // Test that coefficient derivation is consistent across different row counts
251- // but same rowSize
252- configs := []struct {
253- k int
254- n int
255- }{
256- {4 , 4 },
257- {8 , 8 },
258- {16 , 16 },
259- }
260-
261- rowSize := 128
250+ // Coefficient derivation must be deterministic for a given
251+ // (rowRoot, K, N, RowSize) tuple, and must differ when any of those
252+ // transcript inputs change.
262253 rowRoot := sha256 .Sum256 ([]byte ("consistent root" ))
254+ base := & Config {K : 8 , N : 8 , RowSize : 128 , WorkerCount : 1 }
263255
264- var prevCoeffs []field. GF128
256+ baseCoeffs := deriveCoefficients ( rowRoot , base . K , base . N , base . RowSize )
265257
266- for i , tc := range configs {
267- config := & Config {
268- K : tc .k ,
269- N : tc .n ,
270- RowSize : rowSize ,
271- WorkerCount : 1 ,
258+ // Same inputs → identical output.
259+ again := deriveCoefficients (rowRoot , base .K , base .N , base .RowSize )
260+ if len (again ) != len (baseCoeffs ) {
261+ t .Fatalf ("deterministic: length mismatch: got %d want %d" , len (again ), len (baseCoeffs ))
262+ }
263+ for i := range baseCoeffs {
264+ if ! field .Equal128 (baseCoeffs [i ], again [i ]) {
265+ t .Fatalf ("deterministic: coefficient %d differs" , i )
272266 }
267+ }
273268
274- coeffs := deriveCoefficients ( rowRoot , config . RowSize )
275-
276- // All configs with same rowSize should produce same coefficients
277- if i > 0 {
278- if len ( coeffs ) != len ( prevCoeffs ) {
279- t . Fatalf ( " Config %d: coefficient count differs" , i )
280- }
281-
282- for j := range coeffs {
283- if ! field . Equal128 ( coeffs [ j ], prevCoeffs [ j ]) {
284- t . Errorf ( "Config %d: coefficient %d differs" , i , j )
285- }
286- }
269+ // Varying any of K, N, RowSize must change the coefficients.
270+ variants := [] struct {
271+ name string
272+ config * Config
273+ } {
274+ { "different K" , & Config { K : 4 , N : 8 , RowSize : 128 , WorkerCount : 1 }},
275+ { "different N" , & Config { K : 8 , N : 16 , RowSize : 128 , WorkerCount : 1 }},
276+ { "different RowSize" , & Config { K : 8 , N : 8 , RowSize : 256 , WorkerCount : 1 }},
277+ }
278+ for _ , v := range variants {
279+ got := deriveCoefficients ( rowRoot , v . config . K , v . config . N , v . config . RowSize )
280+ if equalGF128Slice ( got , baseCoeffs ) {
281+ t . Errorf ( "%s: coefficients unexpectedly equal to base" , v . name )
287282 }
283+ }
284+ }
288285
289- prevCoeffs = coeffs
286+ func equalGF128Slice (a , b []field.GF128 ) bool {
287+ if len (a ) != len (b ) {
288+ return false
289+ }
290+ for i := range a {
291+ if ! field .Equal128 (a [i ], b [i ]) {
292+ return false
293+ }
290294 }
295+ return true
291296}
0 commit comments