cryptonote: sort tx_extra fields

This removes some small amount of fingerprinting entropy.
There is no consensus rule to require this since this field
is technically free form, and a transaction is free to have
custom data in it.
This commit is contained in:
moneromooo-monero 2018-08-03 10:21:08 +00:00
parent 91c7d68b2d
commit 9907ea0694
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
5 changed files with 177 additions and 1 deletions

View file

@ -33,6 +33,8 @@
#include <vector>
#include "common/util.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/tx_extra.h"
#include "cryptonote_core/cryptonote_tx_utils.h"
namespace
@ -203,3 +205,85 @@ TEST(validate_parse_amount_case, validate_parse_amount)
r = cryptonote::parse_amount(res, "1 00.00 00");
ASSERT_FALSE(r);
}
TEST(sort_tx_extra, empty)
{
std::vector<uint8_t> extra, sorted;
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted));
ASSERT_EQ(extra, sorted);
}
TEST(sort_tx_extra, pubkey)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted));
ASSERT_EQ(extra, sorted);
}
TEST(sort_tx_extra, two_pubkeys)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230,
1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted));
ASSERT_EQ(extra, sorted);
}
TEST(sort_tx_extra, keep_order)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230,
2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted));
ASSERT_EQ(extra, sorted);
}
TEST(sort_tx_extra, switch_order)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
const uint8_t expected_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230,
2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted));
std::vector<uint8_t> expected(&expected_arr[0], &expected_arr[0] + sizeof(expected_arr));
ASSERT_EQ(expected, sorted);
}
TEST(sort_tx_extra, invalid)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {1};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_FALSE(cryptonote::sort_tx_extra(extra, sorted));
}
TEST(sort_tx_extra, invalid_suffix_strict)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_FALSE(cryptonote::sort_tx_extra(extra, sorted));
}
TEST(sort_tx_extra, invalid_suffix_partial)
{
std::vector<uint8_t> sorted;
const uint8_t extra_arr[] = {2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1};
const uint8_t expected_arr[] = {2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
ASSERT_TRUE(cryptonote::sort_tx_extra(extra, sorted, true));
std::vector<uint8_t> expected(&expected_arr[0], &expected_arr[0] + sizeof(expected_arr));
ASSERT_EQ(sorted, expected);
}