class PartialMerkleTreeFormatUtils {

    public static boolean hasExpectedSize(byte[] pmtSerialized) {
        try {
            VarInt hashesCount = getHashesCount(pmtSerialized);
            VarInt flagBitsCount = getFlagBitsCount(pmtSerialized);
            int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH
                    + hashesCount.getOriginalSizeInBytes()
                    + flagBitsCount.getOriginalSizeInBytes(),
                    Math.toIntExact(flagBitsCount.value)),
                    Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH)
            );
            return pmtSerialized.length == declaredSize;
        } catch (RuntimeException e) {
            return false;
        }
    }

}