BBVA / qed

The scalable, auditable and high-performance tamper-evident log project
https://qed.readthedocs.io/
Apache License 2.0
95 stars 19 forks source link

HyperTree: bug adding nodes. #38

Closed jllucas closed 5 years ago

jllucas commented 6 years ago

Given the following test in "hyper>tree_test.go":

func TestAdd(t *testing.T) {

    testCases := []struct {
        eventDigest      []byte
        expectedRootHash []byte
    }{
        {[]byte{0x0}, []byte{0x0}},
        {[]byte{0x1}, []byte{0x1}},
        {[]byte{0x2}, []byte{0x3}},
        {[]byte{0x3}, []byte{0x0}},
        {[]byte{0x4}, []byte{0x4}},
        {[]byte{0x5}, []byte{0x1}},
        {[]byte{0x6}, []byte{0x7}},
        {[]byte{0x7}, []byte{0x0}},
        {[]byte{0x8}, []byte{0x8}},
        {[]byte{0x9}, []byte{0x1}},
    }

    hasher := new(hashing.XorHasher)

    leaves, close := openBPlusStorage()
    defer close()
    cache := cache.NewSimpleCache(2)
    tree := NewFakeTree(string(0x0), cache, leaves, hasher)

    for i, c := range testCases {
        index := make([]byte, 8)
        binary.LittleEndian.PutUint64(index, uint64(i))

        rh, err := tree.Add(c.eventDigest, index)
        assert.Nil(t, err, "Error adding to the tree: %v", err)
        assert.Equal(t, c.expectedRootHash, rh, "Incorrect root hash for index %d", i)
    }

}

And printing insertions until test 2:

;;;;
: [0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0]
;;;;
: [0 0 0 0 0 0 0 0 0] [1 0 0 0 0 0 0 0]
: [1 0 0 0 0 0 0 0 0] [1 0 0 0 0 0 0 0]
;;;;
: [0 0 0 0 0 0 0 0 0] [2 0 0 0 0 0 0 0]
: [1 0 0 0 0 0 0 0 0] [2 0 0 0 0 0 0 0]
: [2 0 0 0 0 0 0 0 0] [2 0 0 0 0 0 0 0]

It happens that when inserting a new index in hyper-tree, the function "tree.fromStorage" returns the same value to all existing leafs.