Open odeke-em opened 3 years ago
I can also get here by invoking
smn, smv := NewSimpleMap(), NewSimpleMap()
smt := NewSparseMerkleTree(smn, smv, sha256.New())
smn.Set([]byte("key"), []byte("v"))
smn.Set([]byte("not my root"), []byte("v"))
smt.ProveUpdatableForRoot([]byte("key"), []byte("not my root"))
@odeke-em This is interesting.
I guess it passes fuzzing (and also my eyes), because here you do the set via the MapStore interface, not directly to the tree using smt.Update
.
I don't see any issue with additional safety checks to be able to fail gracefully if the user passed in "invalid" input. Especially something like this, where the panic might not manifest for a while.
Is this resolved?
Not yet!
If we look at this code here https://github.com/celestiaorg/smt/blob/a99c0f5249884312ab8e6864fe165371c0f461ba/treehasher.go#L68-L70
we notice that the authors assumed that we'd always have data with a length of at least 33 bytes. However, this code unfortunately doesn't recall that to create a SparseMerkleTree, we need to pass in the nodes MapStore as well as the values MapStore. If we run this code, we'll get a panic:
Suggestion
Given this package is going to be general purpose, we need to also be defensive about code whose limits that we know we control, we should return errors and be defensive whenever we try to access data with blind bounds
/cc @cuonglm @adlerjohn @liamsi