Skip to content

Commit

Permalink
Merge pull request algorand#5793 from Algo-devops-service/relstable3.…
Browse files Browse the repository at this point in the history
…19.0
  • Loading branch information
algojohnlee authored Oct 20, 2023
2 parents 2296f52 + 536c171 commit d2c172e
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 109 deletions.
16 changes: 8 additions & 8 deletions merklearray/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions merklearray/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (p *SingleLeafProof) GetConcatenatedProof() []byte {
}

// ProofDataToSingleLeafProof receives serialized proof data and uses it to construct a proof object.
func ProofDataToSingleLeafProof(hashTypeData string, treeDepth uint64, proofBytes []byte) (SingleLeafProof, error) {
func ProofDataToSingleLeafProof(hashTypeData string, proofBytes []byte) (SingleLeafProof, error) {
hashType, err := crypto.UnmarshalHashType(hashTypeData)
if err != nil {
return SingleLeafProof{}, err
Expand All @@ -158,7 +158,7 @@ func ProofDataToSingleLeafProof(hashTypeData string, treeDepth uint64, proofByte
var proof SingleLeafProof

proof.HashFactory = crypto.HashFactory{HashType: hashType}
proof.TreeDepth = uint8(treeDepth)
proof.TreeDepth = 0

digestSize := proof.HashFactory.NewHash().Size()
if len(proofBytes)%digestSize != 0 {
Expand All @@ -172,6 +172,7 @@ func ProofDataToSingleLeafProof(hashTypeData string, treeDepth uint64, proofByte
copy(d[:], proofBytes)
proofPath = append(proofPath, d[:])
proofBytes = proofBytes[len(d):]
proof.TreeDepth++
}

proof.Path = proofPath
Expand Down
11 changes: 7 additions & 4 deletions merklearray/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ func TestConcatenatedProofsMissingChild(t *testing.T) {
err = Verify(tree.Root(), map[uint64]crypto.Hashable{6: array[6]}, newP.ToProof())
a.NoError(err)

recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), uint64(p.TreeDepth), concatenatedProof)
recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), concatenatedProof)
a.NoError(err)
a.Equal(recomputedProof.TreeDepth, p.TreeDepth)

// verify that we can reconstruct the original singleLeafProof from the concatenated proof
err = Verify(tree.Root(), map[uint64]crypto.Hashable{6: array[6]}, recomputedProof.ToProof())
Expand Down Expand Up @@ -189,8 +190,9 @@ func TestConcatenatedProofsFullTree(t *testing.T) {
err = Verify(tree.Root(), map[uint64]crypto.Hashable{6: array[6]}, newP.ToProof())
a.NoError(err)

recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), uint64(p.TreeDepth), concatenatedProof)
recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), concatenatedProof)
a.NoError(err)
a.Equal(recomputedProof.TreeDepth, p.TreeDepth)

// verify that we can reconstruct the original singleLeafProof from the concatenated proof
err = Verify(tree.Root(), map[uint64]crypto.Hashable{6: array[6]}, recomputedProof.ToProof())
Expand Down Expand Up @@ -218,8 +220,9 @@ func TestConcatenatedProofsOneLeaf(t *testing.T) {
err = Verify(tree.Root(), map[uint64]crypto.Hashable{0: array[0]}, newP.ToProof())
a.NoError(err)

recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), uint64(p.TreeDepth), concatenatedProof)
recomputedProof, err := ProofDataToSingleLeafProof(p.HashFactory.HashType.String(), concatenatedProof)
a.NoError(err)
a.Equal(recomputedProof.TreeDepth, p.TreeDepth)

// verify that we can reconstruct the original singleLeafProof from the concatenated proof
err = Verify(tree.Root(), map[uint64]crypto.Hashable{0: array[0]}, recomputedProof.ToProof())
Expand All @@ -230,7 +233,7 @@ func TestProofDeserializationError(t *testing.T) {
partitiontest.PartitionTest(t)
a := require.New(t)

_, err := ProofDataToSingleLeafProof(crypto.Sha256.String(), 1, []byte{1})
_, err := ProofDataToSingleLeafProof(crypto.Sha256.String(), []byte{1})
a.ErrorIs(err, ErrProofLengthDigestSizeMismatch)
}

Expand Down
24 changes: 12 additions & 12 deletions merklesignature/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions merklesignature/persistentMerkleSignatureScheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func (s *Secrets) Persist(store db.Accessor) error {
return fmt.Errorf("Secrets.Persist: %w", ErrKeyLifetimeIsZero)
}
round := indexToRound(s.FirstValid, s.KeyLifetime, 0)
encodedKey := protocol.GetEncodingBuf()
encodedBuf := protocol.GetEncodingBuf()
encodedKey := encodedBuf.Bytes()
err := store.Atomic(func(ctx context.Context, tx *sql.Tx) error {
err := InstallStateProofTable(tx) // assumes schema table already exists (created by partInstallDatabase)
if err != nil {
Expand Down Expand Up @@ -126,7 +127,7 @@ func (s *Secrets) Persist(store db.Accessor) error {

return nil
})
protocol.PutEncodingBuf(encodedKey)
protocol.PutEncodingBuf(encodedBuf.Update(encodedKey))
if err != nil {
return fmt.Errorf("Secrets.Persist: %w", err)
}
Expand Down
Loading

0 comments on commit d2c172e

Please sign in to comment.