Use absolute addressing in HStar2#765
Conversation
integration/maptest/map_test.go
Outdated
| desc: "maphasher batch", | ||
| HashStrategy: trillian.HashStrategy_TEST_MAP_HASHER, | ||
| batchSize: 64, numBatches: 32, | ||
| batchSize: 1, numBatches: 1, |
merkle/hstar2.go
Outdated
| depth := len(prefix) * 8 | ||
| totalDepth := depth + subtreeDepth | ||
| if totalDepth > s.hasher.BitLen() { | ||
| return nil, ErrNegativeTreeLevelOffset |
merkle/hstar2.go
Outdated
| func(depth int, index *big.Int, hash []byte) error { | ||
| return set(treeDepth-depth, index, hash) | ||
| }) | ||
| offset := new(big.Int).SetBytes(prefix) |
| return h, nil | ||
| } | ||
| } | ||
| height := s.hasher.BitLen() - depth |
There was a problem hiding this comment.
TODO: convert hashers back to accepting depth arguments
merkle/hstar2_test.go
Outdated
| } | ||
| ret = append(ret, HStar2LeafHash{prefix, root}) | ||
|
|
||
| index := new(big.Int).SetBytes(prefix) |
There was a problem hiding this comment.
Use NewNode Functions
merkle/sparse_merkle_tree.go
Outdated
| return | ||
| } | ||
| leaves = append(leaves, HStar2LeafHash{Index: new(big.Int).SetBytes(ih.index), LeafHash: ih.hash}) | ||
| node := storage.NewNodeIDFromPrefixSuffix(ih.index, storage.Suffix{}, s.hasher.BitLen()) |
merkle/sparse_merkle_tree.go
Outdated
| nodesToStore = append(nodesToStore, | ||
| storage.Node{ | ||
| NodeID: storage.NewNodeIDFromHash(bytes.Join([][]byte{s.prefix, ih.index}, []byte{})), | ||
| NodeID: storage.NewNodeIDFromHash(ih.index), |
There was a problem hiding this comment.
XXX: should this be the above node?
b1e3f57 to
0248a22
Compare
|
Can we drop the test timeout change from the PR? |
|
Now that we're running
WDYT? |
|
Can we get a rough breakdown of where the time is being spent? I'm reluctant to have people waiting > 10 mins for test runs but if it's necessary to ensure correctness then we might have to. |
|
Here's the output of a run on my local machine (which is a bit faster than travis). It's clear that the large batch test is taking up almost all of the time. The batch test is running 32 batches of size 64 = 2048 leaves being written and read back out. === RUN TestInclusion |
|
Do they run at this speed on Travis? I think 30 seconds isn't unreasonable. But we keep adding tests the cumulatively take a long time to run. |
|
They run much slower on travis. I've set the timeout back to 5 minutes and set travis to only run the short version of tests. I should note here that the full integration tests also get run without a timeout through |
07bb675 to
23edc87
Compare
|
I think this PR needs a rebase / merge now? |
|
Rebased and ready for review |
| func ParseSuffix(s string) (Suffix, error) { | ||
| b, err := base64.StdEncoding.DecodeString(s) | ||
| if err != nil { | ||
| return Suffix{}, err |
There was a problem hiding this comment.
Does nil, err not work?
There was a problem hiding this comment.
nil doesn't work here because the return argument is Suffix rather than *Suffix.
Fear not, I have more pull requests if you so desire :-)
| leaves: []*trillian.MapLeaf{ | ||
| {Index: h2b("0000000000000000000000000000000000000000000000000000000000000000"), LeafValue: []byte("A")}, | ||
| {Index: h2b("0000000000000000000000000000000000000000000000000000000000000001"), LeafValue: []byte("B")}, | ||
| {Index: h2b("0000000000000000000000000000000000000000000000000000000000000002"), LeafValue: []byte("C")}, |
There was a problem hiding this comment.
How about a multi byte leaf value test, just for paranoia. Might also want to test what happens if the leaf value is empty.
There was a problem hiding this comment.
The empty leaf case is both in the just merged TestLeafHistory and in TestNonexistantLeaf. I can add here as well.
merkle/hstar2_test.go
Outdated
| b = append([]byte{0}, b...) | ||
| subtreeDepth := s.hasher.BitLen() - prefixSize | ||
| prefix := lh[i].Index.Bytes() | ||
| // ensure we've got any chopped off leading zero bytes |
There was a problem hiding this comment.
I don't think that comment is fully clear. I know it was there before but how about "left pad prefix with any zero bytes that were previously removed".
| want []byte | ||
| }{ | ||
| {h2b(""), 1, h2b("0801")}, | ||
| {h2b("00"), 1, h2b("0801")}, |
There was a problem hiding this comment.
Not testing any invalid cases?
|
PTAL |
Secure versions of
HashEmptytake the node's address into account. See #670.This PR modifies
HStar2and its callers to useNodeIDs for absolute addressing in order to supply full paths to the hashing functions.HStar2 Changes
HStar2in its current form only uses subtree relative addressing.This PR modifies the
HStar2algorithm from operating in terms of subtree height to absolute depth.from
hStar2b(n int, values []HStar2LeafHash, offset *big.Int)to
hStar2b(depth, maxDepth int, values []HStar2LeafHash, offset *big.Int)And it also provides
HStar2Nodeswith the prefix of the subtree it is operating on.NodeID Changes
In order to provide correct conversions to/from
Hstar2LeafHash,NodeID,PrefixandSuffixthe following functions are added and tested:ParseSuffixNodeID.BigIntNewNodeIDFromBigIntNewNodeIDFromPrefixSuffixVerifier Changes
On the verification side, the verification algorithm is also modified to provide a correct path to
HashEmpty.Closes #670
Rebased on #761 and #772