Skip to content

Batch Merkle Proof Serialization & Deserialization #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ApexTheory
Copy link
Contributor

@ApexTheory ApexTheory commented Nov 11, 2021

Hi @kushti please review at your convenience. Let me know if any additional functionality is required.

Close #86

}
}

property("indices serialization + deserialization") {
Copy link
Contributor Author

@ApexTheory ApexTheory Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this test (along with proofs test below) is redundant. Should I remove?
Although perhaps I can force negative test scenarios here (whereas they would fail the bounds check as a BatchMerkleProof object).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably redundant yes

Copy link
Contributor Author

@ApexTheory ApexTheory Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left these tests in which directly use the private[serialization] methods. The BatchMerkleProoftest now uses the new serialize and deserialize methods.

import scorex.crypto.authds.{EmptyByteArray, Side}
import scorex.crypto.hash.Digest

class BatchMerkleProofSerialization[D <: Digest] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BatchMerkleProofSerialization => BatchMerkleProofSerializer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D <: Digest => D <: Digest32 , as serialization assumes hashes of 256 bits.

Better to use DigestSize = 32 constant instead of magic value in the class ( DigestSize + 4 instead of 36), then it will be simpler to retarget for hashed of 512 bits if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and went a bit further with the constants use to make the code more readable.

})
.toSeq
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth to make all the tests private[serialization] (to be used in tests only), and introduce serialize(b: ): Array[Byte] / deserialize(arr:Array[Byte): Try[BatchMerkleProof] methods. Please node that deserialization may faile if e.g. invalid bytes are provided. thus Try[BatchMerkleProof]. would be good to have a test for improper bytes provided (e.g. just 2 any bytes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}

property("indices serialization + deserialization") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably redundant yes

@kushti kushti merged commit f08152c into input-output-hk:master Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialization for batch Merkle proofs
2 participants