@@ -261,3 +261,56 @@ func TestRefConsistencyProof(t *testing.T) {
261261 })
262262 }
263263}
264+
265+ func TestRefSubtreeConsistencyProof (t * testing.T ) {
266+ entries := LeafInputs ()
267+ hasher := rfc6962 .DefaultHasher
268+ fullRoot8 := refRootHash (entries [:8 ], hasher )
269+
270+ for _ , tc := range []struct {
271+ start uint64
272+ end uint64
273+ size uint64
274+ known bool
275+ want [][]byte
276+ }{
277+ // Empty subtrees (start == end) always return nil (empty proof).
278+ {start : 0 , end : 0 , size : 8 , known : true , want : nil },
279+ {start : 4 , end : 4 , size : 8 , known : true , want : nil },
280+ {start : 8 , end : 8 , size : 8 , known : true , want : nil },
281+ // Invalid ranges return nil.
282+ {start : 5 , end : 3 , size : 8 , known : true , want : nil },
283+ {start : 0 , end : 10 , size : 8 , known : true , want : nil },
284+ // Full tree [0, 8) in size 8.
285+ {start : 0 , end : 8 , size : 8 , known : true , want : nil },
286+ {start : 0 , end : 8 , size : 8 , known : false , want : [][]byte {fullRoot8 }},
287+ // Left half [0, 4) in size 8 requires the root of the right half [4, 8).
288+ {start : 0 , end : 4 , size : 8 , known : true , want : [][]byte {
289+ hd ("6b47aaf29ee3c2af9af889bc1fb9254dabd31177f16232dd6aab035ca39bf6e4" ),
290+ }},
291+ // Prefix subtree consistency cases matching TestRefConsistencyProof (start=0):
292+ {start : 0 , end : 1 , size : 1 , known : true , want : nil },
293+ {start : 0 , end : 1 , size : 8 , known : true , want : [][]byte {
294+ hd ("96a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7" ),
295+ hd ("5f083f0a1a33ca076a95279832580db3e0ef4584bdff1f54c8a360f50de3031e" ),
296+ hd ("6b47aaf29ee3c2af9af889bc1fb9254dabd31177f16232dd6aab035ca39bf6e4" ),
297+ }},
298+ {start : 0 , end : 2 , size : 5 , known : true , want : [][]byte {
299+ hd ("5f083f0a1a33ca076a95279832580db3e0ef4584bdff1f54c8a360f50de3031e" ),
300+ hd ("bc1a0643b12e4d2d7c77918f44e0f4f79a838b6cf9ec5b5c283e1f4d88599e6b" ),
301+ }},
302+ {start : 0 , end : 6 , size : 8 , known : true , want : [][]byte {
303+ hd ("0ebc5d3437fbe2db158b9f126a1d118e308181031d0a949f8dededebc558ef6a" ),
304+ hd ("ca854ea128ed050b41b35ffc1b87b8eb2bde461e9e3b5596ece6b9d5975a0ae0" ),
305+ hd ("d37ee418976dd95753c1c73862b9398fa2a2cf9b4ff0fdfe8b30cd95209614b7" ),
306+ }},
307+ } {
308+ t .Run (fmt .Sprintf ("start:%d end:%d size:%d known:%t" , tc .start , tc .end , tc .size , tc .known ), func (t * testing.T ) {
309+ got := refSubtreeConsistencyProof (tc .start , tc .end , entries [:tc .size ], tc .known , hasher )
310+ if diff := cmp .Diff (got , tc .want ); diff != "" {
311+ t .Errorf ("refSubtreeConsistencyProof: diff (-got +want)\n %s" , diff )
312+ }
313+ })
314+ }
315+ }
316+
0 commit comments