Skip to content

Commit 754b77d

Browse files
committed
spcial case when a subtree len is a pow of 2
1 parent eb0fa9a commit 754b77d

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

proof/proof.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ func SubtreeConsistency(start, end, size uint64) (Nodes, error) {
139139
// into this node in the tree of the given size.
140140
p := nodes(index, level, size)
141141

142-
// Handle the case when end is a power of 2.
143-
// TODO: do we also need to do taht for a full subtree?
144-
// if first node is the root of the subtree.
145-
if index == 0 {
142+
// Handle the case when the subtree size if a power of 2.
143+
if (end-start)&(end-start-1) == 0 {
146144
return p.skipFirst(), nil
147145
}
148146
return p, nil

proof/proof_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,16 @@ func TestSubtreeConsistency(t *testing.T) {
484484
{start: 0, end: 7, size: 8, want: nodes(
485485
id(0, 6), id(0, 7), id(1, 2), id(2, 0))}, // g h cc aaa
486486
// start > 0
487-
{start: 1, end: 2, size: 3, want: rehash(2, 3, id(0, 1), id(0, 0), id(0, 2))}, // b a c
488-
{start: 1, end: 2, size: 5, want: rehash(3, 4, id(0, 1), id(0, 0), id(1, 1), id(0, 4))}, // b a bb e
489-
{start: 2, end: 4, size: 5, want: rehash(2, 3, id(1, 1), id(1, 0), id(0, 4))}, // bb aa e
490-
{start: 1, end: 2, size: 7, want: rehash(3, 5, id(0, 1), id(0, 0), id(1, 1), id(0, 6), id(1, 2))}, // b a bb g cc
491-
{start: 2, end: 4, size: 10, want: rehash(3, 4, id(1, 1), id(1, 0), id(2, 1), id(1, 4))}, // bb aa bbb ee
487+
{start: 1, end: 2, size: 3, want: rehash(1, 2, id(0, 0), id(0, 2))}, // a c
488+
{start: 1, end: 2, size: 5, want: rehash(2, 3, id(0, 0), id(1, 1), id(0, 4))}, // a bb e
489+
{start: 2, end: 4, size: 5, want: rehash(1, 2, id(1, 0), id(0, 4))}, // aa e
490+
{start: 1, end: 2, size: 7, want: rehash(2, 4, id(0, 0), id(1, 1), id(0, 6), id(1, 2))}, // a bb g cc
491+
{start: 2, end: 4, size: 10, want: rehash(2, 3, id(1, 0), id(2, 1), id(1, 4))}, // aa bbb ee
492+
{start: 4, end: 6, size: 10, want: rehash(2, 3, id(1, 3), id(2, 0), id(1, 4))}, // dd aaa ee
492493
{start: 4, end: 7, size: 11, want: rehash(4, 6, // ccc=hash(ee,k)
493494
id(0, 6), id(0, 7), id(1, 2), id(2, 0), id(0, 10), id(1, 4))}, // g h cc aaa k ee
494-
{start: 4, end: 8, size: 11, want: rehash(2, 4, // ccc=hash(ee,k)
495-
id(2, 1), id(2, 0), id(0, 10), id(1, 4))}, // bbb aaa k ee
495+
{start: 4, end: 8, size: 11, want: rehash(1, 3, // ccc=hash(ee,k)
496+
id(2, 0), id(0, 10), id(1, 4))}, // aaa k ee
496497
{start: 8, end: 13, size: 15, want: rehash(2, 3,
497498
id(0, 12), id(0, 13), id(0, 14), id(2, 2), id(3, 0))}, // m n o ccc aaaa
498499
{start: 8, end: 14, size: 15, want: rehash(1, 2, // hh=hash(o)
@@ -522,16 +523,16 @@ func TestSubtreeConsistency(t *testing.T) {
522523
{start: 0, end: 1, size: 7, want: rehash(2, 4, // bbb=hash(cc,g)
523524
id(0, 1), id(1, 1), id(0, 6), id(1, 2))}, // b bb g cc
524525
// start > 0
525-
{start: 2, end: 4, size: 6, want: rehash(2, 3, // bbb=hash(cc)
526-
id(1, 1), id(1, 0), id(1, 2))}, // bb, aa, cc
526+
{start: 2, end: 4, size: 6, want: rehash(1, 2, // bbb=hash(cc)
527+
id(1, 0), id(1, 2))}, // aa, cc
527528
{start: 4, end: 7, size: 9, want: rehash(4, 5, // bbbb=hash(i)
528529
id(0, 6), id(0, 7), id(1, 2), id(2, 0), id(0, 8))}, // g h cc aaa i
529530
{start: 4, end: 7, size: 10, want: rehash(4, 5, // bbbb=hash(ee)
530531
id(0, 6), id(0, 7), id(1, 2), id(2, 0), id(1, 4))}, // g h cc aaa ee
531-
{start: 4, end: 8, size: 10, want: rehash(2, 3,
532-
id(2, 1), id(2, 0), id(1, 4))}, // cc
533-
{start: 2, end: 3, size: 9, want: rehash(4, 5, // bbbb=hash(i)
534-
id(0, 2), id(0, 3), id(1, 0), id(2, 1), id(0, 8))}, // b bb g cc
532+
{start: 4, end: 8, size: 10, want: rehash(1, 2,
533+
id(2, 0), id(1, 4))}, // cc
534+
{start: 2, end: 3, size: 9, want: rehash(3, 4, // bbbb=hash(i)
535+
id(0, 3), id(1, 0), id(2, 1), id(0, 8))}, // b bb g cc
535536

536537
// Some rehashes in the middle of the returned list.
537538
{start: 0, end: 10, size: 15, want: rehash(2, 4,

0 commit comments

Comments
 (0)