google / trillian

A transparent, highly scalable and cryptographically verifiable data store.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API returns Tree size = 0 for Preordered log

gremlin97 opened this issue · comments

  • While trying to obtain the Inclusion proof for a data value using the getInclusionRequest, I tried to find the root size of the preordered log(To pass as an argument). I used the same API like the one for a normal log but the tree size returned was zero. I have attached the code snippet below. Thanks in advance!

  • Code Snippet

//Function to return inclusion proof of a data value
func (tlc *trillianLogClient) getIncProof(in *preferenceproto.PostPreferenceRequest, index int64) *trillian.Proof {
	logRootReq := &trillian.GetLatestSignedLogRootRequest{
		LogId: tlc.logID,
	}
	//Returns information about the current root of the Merkle tree for the log, including the tree size, hash value, timestamp and signature
	logRootResp, err := tlc.client.GetLatestSignedLogRoot(context.Background(), logRootReq)
	if err != nil {
		log.Fatal(err)
	}

	var root types.LogRootV1
	if err := root.UnmarshalBinary(logRootResp.SignedLogRoot.LogRoot); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Root is %v\n", root)

	//Inclusion request struct
	inclusionReq := &trillian.GetInclusionProofRequest{
		LogId:     *tPlogID,
		LeafIndex: index,
		TreeSize:  int64(root.TreeSize),
	}
	fmt.Printf("Root size is %v\n", int64(root.TreeSize))
	//Getting inclusion proof
	inclusionResp, _ := tlc.client.GetInclusionProof(context.Background(), inclusionReq)
	fmt.Printf("Inclusion Resp: %v", inclusionResp)
	proof := inclusionResp.GetProof()
	fmt.Printf("Proof: %v", proof)
	return proof
}



  • Log
Root is {0 [227 176 196 66 152 252 28 20 154 251 244 200 153 111 185 36 39 174 65 228 100 155 147 76 164 149 153 27 120 82 184 85] 1590741614435494808 0 []}
Root size is 0
Inclusion Resp: <nil>Proof: <nil>

The data for tree as shown in sql adminer:
Screenshot from 2020-05-29 16-43-13

For tree revision, it seems intrate timestamp is 0. Is it related to isue?
Screenshot from 2020-05-29 16-49-47

In the code that is inserting leaves into a preordered tree, you need to make sure that every index from 0..N is filled with a leaf. Any gaps will prevent the tree being constructed properly. Do you have any gaps in your ranges?

@gremlin97 Did you find the cause of the problem? As Martin says, for a tree to grow to size N, all leaves between 0..N-1 must be added. From your second screenshot, it looks like you are missing entries 0 and 1 before entries 2, 3, etc. Also, you need to have a running logsigner because this is the process which builds the tree (which you do have according to the first screenshot).

@prachi2703 The integrate timestamp = 0 is unrelated. For pre-ordered logs this timestamp is unset.

@pavelkalinnikov We were able to solve the issue after following the advice from @mhutchinson.