diff --git a/empty.go b/empty.go index 2115c9d..bc6d8bb 100644 --- a/empty.go +++ b/empty.go @@ -53,7 +53,7 @@ func (Empty) Commitment() *Point { return &id } -func (Empty) GetProofItems(keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { +func (Empty) GetProofItems(Keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { return nil, nil, nil, errors.New("trying to produce a commitment for an empty subtree") } diff --git a/hashednode.go b/hashednode.go index bd53c9d..c0f75c4 100644 --- a/hashednode.go +++ b/hashednode.go @@ -58,7 +58,7 @@ func (HashedNode) Commitment() *Point { panic("can not get commitment of a hash node") } -func (HashedNode) GetProofItems(keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { +func (HashedNode) GetProofItems(Keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { return nil, nil, nil, errors.New("can not get the full path, and there is no proof of absence") } diff --git a/proof_ipa.go b/proof_ipa.go index a4a27b0..f694727 100644 --- a/proof_ipa.go +++ b/proof_ipa.go @@ -185,8 +185,8 @@ func (sd StateDiff) Equal(other StateDiff) error { } func GetCommitmentsForMultiproof(root VerkleNode, keys [][]byte, resolver NodeResolverFn) (*ProofElements, []byte, []Stem, error) { - sort.Sort(keylist(keys)) - return root.GetProofItems(keylist(keys), resolver) + sort.Sort(Keylist(keys)) + return root.GetProofItems(Keylist(keys), resolver) } // getProofElementsFromTree factors the logic that is used both in the proving and verification methods. It takes a pre-state diff --git a/proof_test.go b/proof_test.go index 5ee7680..97e0480 100644 --- a/proof_test.go +++ b/proof_test.go @@ -453,7 +453,7 @@ func TestProofDeserialize(t *testing.T) { } _ = deserialized - pe, _, _, err := root.GetProofItems(keylist{absentkey[:]}, nil) + pe, _, _, err := root.GetProofItems(Keylist{absentkey[:]}, nil) if err != nil { t.Fatal(err) } @@ -735,7 +735,7 @@ func TestStatelessDeserialize(t *testing.T) { string(fourtyKeyTest): fourtyKeyTest, string(ffx32KeyTest): fourtyKeyTest, } - proveKeys := keylist{zeroKeyTest, fourtyKeyTest} + proveKeys := Keylist{zeroKeyTest, fourtyKeyTest} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -748,7 +748,7 @@ func TestStatelessDeserializeMissingLeafNode(t *testing.T) { string(oneKeyTest): fourtyKeyTest, string(ffx32KeyTest): fourtyKeyTest, } - proveKeys := keylist{zeroKeyTest, fourtyKeyTest} + proveKeys := Keylist{zeroKeyTest, fourtyKeyTest} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -760,7 +760,7 @@ func TestStatelessDeserializeAbsentValueInExistingLeafNode(t *testing.T) { string(zeroKeyTest): fourtyKeyTest, string(ffx32KeyTest): fourtyKeyTest, } - proveKeys := keylist{zeroKeyTest, oneKeyTest} + proveKeys := Keylist{zeroKeyTest, oneKeyTest} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -774,7 +774,7 @@ func TestStatelessDeserializeDepth2(t *testing.T) { string(key1): fourtyKeyTest, string(ffx32KeyTest): fourtyKeyTest, } - proveKeys := keylist{zeroKeyTest, key1} + proveKeys := Keylist{zeroKeyTest, key1} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -791,7 +791,7 @@ func TestProofVerificationThreeStemsInSameExtensionStatus(t *testing.T) { string(key3_0): fourtyKeyTest, string(key3_1): fourtyKeyTest, } - proveKeys := keylist{zeroKeyTest, key2_0, key3_0, key3_1, key4_0} + proveKeys := Keylist{zeroKeyTest, key2_0, key3_0, key3_1, key4_0} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -805,7 +805,7 @@ func TestProofVerificationTwoLeavesWithDifferentValues(t *testing.T) { string(zeroKeyTest): fourtyKeyTest, string(key2): forkOneKeyTest, } - proveKeys := keylist{zeroKeyTest, key2} + proveKeys := Keylist{zeroKeyTest, key2} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -818,7 +818,7 @@ func TestProofOfAbsenceBorderCase(t *testing.T) { insertKVs := map[string][]byte{ string(oneKeyTest): fourtyKeyTest, } - proveKeys := keylist{oneKeyTest, key1} + proveKeys := Keylist{oneKeyTest, key1} testSerializeDeserializeProof(t, insertKVs, proveKeys) } @@ -831,12 +831,12 @@ func TestProofOfAbsenceBorderCaseReversed(t *testing.T) { insertKVs := map[string][]byte{ string(key1): fourtyKeyTest, } - proveKeys := keylist{oneKeyTest, key1} + proveKeys := Keylist{oneKeyTest, key1} testSerializeDeserializeProof(t, insertKVs, proveKeys) } -func testSerializeDeserializeProof(t *testing.T, insertKVs map[string][]byte, proveKeys keylist) { +func testSerializeDeserializeProof(t *testing.T, insertKVs map[string][]byte, proveKeys Keylist) { t.Helper() root := New() @@ -1088,7 +1088,7 @@ func TestGenerateProofWithOnlyAbsentKeys(t *testing.T) { // Create a proof with a key with the same first byte, but different second byte (i.e: absent). absentKey, _ := hex.DecodeString("4010000000000000000000000000000000000000000000000000000000000000") - proof, cis, zis, yis, err := MakeVerkleMultiProof(root, nil, keylist{absentKey}, nil) + proof, cis, zis, yis, err := MakeVerkleMultiProof(root, nil, Keylist{absentKey}, nil) if err != nil { t.Fatal(err) } @@ -1113,7 +1113,7 @@ func TestGenerateProofWithOnlyAbsentKeys(t *testing.T) { } // From the rebuilt tree, validate the proof. - pe, _, _, err := GetCommitmentsForMultiproof(droot, keylist{absentKey}, nil) + pe, _, _, err := GetCommitmentsForMultiproof(droot, Keylist{absentKey}, nil) if err != nil { t.Fatal(err) } @@ -1168,7 +1168,7 @@ func TestDoubleProofOfAbsence(t *testing.T) { // in that leaf node. i.e: two proof of absence in the same leaf node with no proof of presence. key2, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000100") key3, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000200") - proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, keylist{key2, key3}, nil) + proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, Keylist{key2, key3}, nil) serialized, statediff, err := SerializeProof(proof) if err != nil { @@ -1217,7 +1217,7 @@ func TestProveAbsenceInEmptyHalf(t *testing.T) { key2, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000100") key3, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000") - proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, keylist{key2, key3}, nil) + proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, Keylist{key2, key3}, nil) serialized, statediff, err := SerializeProof(proof) if err != nil { diff --git a/tree.go b/tree.go index cccfa5b..9b39ab3 100644 --- a/tree.go +++ b/tree.go @@ -42,17 +42,17 @@ type ( NodeResolverFn func([]byte) ([]byte, error) ) -type keylist [][]byte +type Keylist [][]byte -func (kl keylist) Len() int { +func (kl Keylist) Len() int { return len(kl) } -func (kl keylist) Less(i, j int) bool { +func (kl Keylist) Less(i, j int) bool { return bytes.Compare(kl[i], kl[j]) == -1 } -func (kl keylist) Swap(i, j int) { +func (kl Keylist) Swap(i, j int) { kl[i], kl[j] = kl[j], kl[i] } @@ -90,7 +90,7 @@ type VerkleNode interface { // returns them breadth-first. On top of that, it returns // one "extension status" per stem, and an alternate stem // if the key is missing but another stem has been found. - GetProofItems(keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) + GetProofItems(Keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) // Serialize encodes the node to RLP. Serialize() ([]byte, error) @@ -908,19 +908,19 @@ func commitNodesAtLevel(nodes []*InternalNode) error { } // groupKeys groups a set of keys based on their byte at a given depth. -func groupKeys(keys keylist, depth byte) []keylist { +func groupKeys(keys Keylist, depth byte) []Keylist { // special case: no key if len(keys) == 0 { - return []keylist{} + return []Keylist{} } // special case: only one key left if len(keys) == 1 { - return []keylist{keys} + return []Keylist{keys} } // there are at least two keys left in the list at this depth - groups := make([]keylist, 0, len(keys)) + groups := make([]Keylist, 0, len(keys)) firstkey, lastkey := 0, 1 for ; lastkey < len(keys); lastkey++ { key := keys[lastkey] @@ -938,7 +938,7 @@ func groupKeys(keys keylist, depth byte) []keylist { return groups } -func (n *InternalNode) GetProofItems(keys keylist, resolver NodeResolverFn) (*ProofElements, []byte, []Stem, error) { +func (n *InternalNode) GetProofItems(keys Keylist, resolver NodeResolverFn) (*ProofElements, []byte, []Stem, error) { var ( groups = groupKeys(keys, n.depth) pe = &ProofElements{ @@ -1490,7 +1490,7 @@ func leafToComms(poly []Fr, val []byte) error { return nil } -func (n *LeafNode) GetProofItems(keys keylist, _ NodeResolverFn) (*ProofElements, []byte, []Stem, error) { // skipcq: GO-R1005 +func (n *LeafNode) GetProofItems(keys Keylist, _ NodeResolverFn) (*ProofElements, []byte, []Stem, error) { // skipcq: GO-R1005 var ( poly [NodeWidth]Fr // top-level polynomial pe = &ProofElements{ diff --git a/tree_test.go b/tree_test.go index 0aace88..9bfebb4 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1025,7 +1025,7 @@ func TestEmptyCommitment(t *testing.T) { t.Fatalf("inserting into the original failed: %v", err) } root.Commit() - pe, _, _, err := root.GetProofItems(keylist{ffx32KeyTest}, nil) + pe, _, _, err := root.GetProofItems(Keylist{ffx32KeyTest}, nil) if err != nil { t.Fatal(err) } @@ -1092,7 +1092,7 @@ func TestGetProofItemsNoPoaIfStemPresent(t *testing.T) { key1, _ := hex.DecodeString("ffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") key2, _ := hex.DecodeString("ffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - _, esses, poas, err := root.GetProofItems(keylist{key1, key2, ffx32KeyTest}, nil) + _, esses, poas, err := root.GetProofItems(Keylist{key1, key2, ffx32KeyTest}, nil) if err != nil { t.Fatal(err) } diff --git a/unknown.go b/unknown.go index 28d2866..a84dcaa 100644 --- a/unknown.go +++ b/unknown.go @@ -51,7 +51,7 @@ func (UnknownNode) Commitment() *Point { return &id } -func (UnknownNode) GetProofItems(keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { +func (UnknownNode) GetProofItems(Keylist, NodeResolverFn) (*ProofElements, []byte, []Stem, error) { return nil, nil, nil, errors.New("can't generate proof items for unknown node") }