Skip to content

Commit

Permalink
Auth sample disqualification transactions added.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSuprunenko committed May 23, 2019
1 parent 97fa012 commit 32d62a0
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 88 deletions.
41 changes: 38 additions & 3 deletions src/cryptonote_basic/cryptonote_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,7 @@ namespace cryptonote
return false;
std::vector<tx_extra_field> tx_extra_fields;
parse_tx_extra(tx.extra, tx_extra_fields);
if(!find_tx_extra_field_by_type(tx_extra_fields, disq))
return false;
return true;
return find_tx_extra_field_by_type(tx_extra_fields, disq);
}

bool graft_is_disqualification(const transaction &tx)
Expand Down Expand Up @@ -1064,4 +1062,41 @@ namespace cryptonote
return true;
}

bool graft_get_disqualification2(const transaction &tx, tx_extra_graft_disqualification2& disq)
{
if(tx.version != 124)
return false;
if(!tx.vin.empty() || !tx.vout.empty() || tx.rct_signatures.txnFee !=0)
return false;
std::vector<tx_extra_field> tx_extra_fields;
parse_tx_extra(tx.extra, tx_extra_fields);
return find_tx_extra_field_by_type(tx_extra_fields, disq);
}

bool graft_is_disqualification2(const transaction &tx)
{
tx_extra_graft_disqualification2 disq;
return graft_get_disqualification2(tx, disq);
}

bool graft_check_disqualification2(const transaction &tx, tx_extra_graft_disqualification2* pdisq)
{
tx_extra_graft_disqualification2 disq;
if(!graft_get_disqualification2(tx, disq))
return false;
{//check signs
std::string item_str;
::serialization::dump_binary(disq.item, item_str);
crypto::hash hash;
crypto::cn_fast_hash(item_str.data(), item_str.size(), hash);
for(auto& si : disq.signers)
{
if(!crypto::check_signature(hash, si.signer_id, si.sign))
return false;
}
}
if(pdisq) *pdisq = std::move(disq);
return true;
}

}
4 changes: 4 additions & 0 deletions src/cryptonote_basic/cryptonote_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ namespace cryptonote
bool graft_is_disqualification(const transaction &tx);
bool graft_check_disqualification(const transaction &tx, tx_extra_graft_disqualification* pdisq = nullptr);

bool graft_get_disqualification2(const transaction &tx, tx_extra_graft_disqualification2& disq);
bool graft_is_disqualification2(const transaction &tx);
bool graft_check_disqualification2(const transaction &tx, tx_extra_graft_disqualification2* pdisq = nullptr);

bool add_extra_nonce_to_tx_extra(std::vector<uint8_t>& tx_extra, const blobdata& extra_nonce);
bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type);
void set_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash& payment_id);
Expand Down
38 changes: 37 additions & 1 deletion src/cryptonote_basic/tx_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define TX_EXTRA_GRAFT_RTA_HEADER_TAG 0x83
#define TX_EXTRA_GRAFT_RTA_SIGNATURES_TAG 0x84
#define TX_EXTRA_GRAFT_DISQUALIFICATION_TAG 0x85
#define TX_EXTRA_GRAFT_DISQUALIFICATION2_TAG 0x86

#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE

Expand Down Expand Up @@ -265,14 +266,48 @@ namespace cryptonote
END_SERIALIZE()
};

struct tx_extra_graft_disqualification2
{
struct disqualification_item
{
std::string payment_id;
uint64_t block_height;
crypto::hash block_hash;
std::vector<crypto::public_key> ids;
BEGIN_SERIALIZE()
FIELD(payment_id)
FIELD(block_height)
FIELD(block_hash)
FIELD(ids)
END_SERIALIZE()
};

struct signer_item
{
crypto::public_key signer_id;
crypto::signature sign;
BEGIN_SERIALIZE()
FIELD(signer_id)
FIELD(sign)
END_SERIALIZE()
};

disqualification_item item;
std::vector<signer_item> signers;
BEGIN_SERIALIZE()
FIELD(item)
FIELD(signers)
END_SERIALIZE()
};

// tx_extra_field format, except tx_extra_padding and tx_extra_pub_key:
// varint tag;
// varint size;
// varint data[];
typedef boost::variant<tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag,
tx_extra_mysterious_minergate, tx_extra_graft_extra, tx_extra_graft_stake_tx,
tx_extra_graft_tx_secret_key, tx_extra_graft_rta_header, tx_extra_graft_rta_signatures,
tx_extra_graft_disqualification> tx_extra_field;
tx_extra_graft_disqualification, tx_extra_graft_disqualification2> tx_extra_field;
}

VARIANT_TAG(binary_archive, cryptonote::tx_extra_padding, TX_EXTRA_TAG_PADDING);
Expand All @@ -286,3 +321,4 @@ VARIANT_TAG(binary_archive, cryptonote::tx_extra_graft_tx_secret_key, TX_EXTRA_G
VARIANT_TAG(binary_archive, cryptonote::tx_extra_graft_rta_header, TX_EXTRA_GRAFT_RTA_HEADER_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_graft_rta_signatures, TX_EXTRA_GRAFT_RTA_SIGNATURES_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_graft_disqualification, TX_EXTRA_GRAFT_DISQUALIFICATION_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_graft_disqualification2, TX_EXTRA_GRAFT_DISQUALIFICATION2_TAG);
8 changes: 8 additions & 0 deletions src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ namespace cryptonote
}
return graft_is_disqualification(tx);
}
if(tx.version == 124)
{
if(tx.vin.size() || tx.vout.size())
{
MERROR_VER("qualification2 tx with non-empty inputs or outputs, rejected for tx id= " << get_transaction_hash(tx));
}
return graft_is_disqualification2(tx);
}
if(!tx.vin.size())
{
MERROR_VER("tx with empty inputs, rejected for tx id= " << get_transaction_hash(tx));
Expand Down
Loading

0 comments on commit 32d62a0

Please sign in to comment.