mirror of
https://github.com/monero-project/monero.git
synced 2025-07-21 23:58:46 -04:00
rct: rework v2 txes into prunable and non prunable data
Nothing is pruned, but this allows easier changes later.
This commit is contained in:
parent
d93746b6d3
commit
93f5c625f0
8 changed files with 154 additions and 91 deletions
|
@ -2279,17 +2279,18 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
|
|||
// II
|
||||
if (rv.type == rct::RCTTypeFull)
|
||||
{
|
||||
rv.MG.II.resize(tx.vin.size());
|
||||
rv.p.MGs.resize(1);
|
||||
rv.p.MGs[0].II.resize(tx.vin.size());
|
||||
for (size_t n = 0; n < tx.vin.size(); ++n)
|
||||
rv.MG.II[n] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
|
||||
rv.p.MGs[0].II[n] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
|
||||
}
|
||||
else if (rv.type == rct::RCTTypeSimple)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(rv.MGs.size() == tx.vin.size(), false, "Bad MGs size");
|
||||
CHECK_AND_ASSERT_MES(rv.p.MGs.size() == tx.vin.size(), false, "Bad MGs size");
|
||||
for (size_t n = 0; n < tx.vin.size(); ++n)
|
||||
{
|
||||
rv.MGs[n].II.resize(1);
|
||||
rv.MGs[n].II[0] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
|
||||
rv.p.MGs[n].II.resize(1);
|
||||
rv.p.MGs[n].II[0] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2577,14 +2578,14 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||
}
|
||||
}
|
||||
|
||||
if (rv.MGs.size() != tx.vin.size())
|
||||
if (rv.p.MGs.size() != tx.vin.size())
|
||||
{
|
||||
LOG_PRINT_L1("Failed to check ringct signatures: mismatched MGs/vin sizes");
|
||||
return false;
|
||||
}
|
||||
for (size_t n = 0; n < tx.vin.size(); ++n)
|
||||
{
|
||||
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.MGs[n].II[0], 32))
|
||||
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.p.MGs[n].II[0], 32))
|
||||
{
|
||||
LOG_PRINT_L1("Failed to check ringct signatures: mismatched key image");
|
||||
return false;
|
||||
|
@ -2630,14 +2631,19 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||
}
|
||||
}
|
||||
|
||||
if (rv.MG.II.size() != tx.vin.size())
|
||||
if (rv.p.MGs.size() != 1)
|
||||
{
|
||||
LOG_PRINT_L1("Failed to check ringct signatures: Bad MGs size");
|
||||
return false;
|
||||
}
|
||||
if (rv.p.MGs[0].II.size() != tx.vin.size())
|
||||
{
|
||||
LOG_PRINT_L1("Failed to check ringct signatures: mismatched II/vin sizes");
|
||||
return false;
|
||||
}
|
||||
for (size_t n = 0; n < tx.vin.size(); ++n)
|
||||
{
|
||||
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.MG.II[n], 32))
|
||||
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.p.MGs[0].II[n], 32))
|
||||
{
|
||||
LOG_PRINT_L1("Failed to check ringct signatures: mismatched II/vin sizes");
|
||||
return false;
|
||||
|
|
|
@ -246,17 +246,12 @@ namespace boost
|
|||
}
|
||||
|
||||
template <class Archive>
|
||||
inline void serialize(Archive &a, rct::rctSig &x, const boost::serialization::version_type ver)
|
||||
inline void serialize(Archive &a, rct::rctSigBase &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
a & x.type;
|
||||
if (x.type != rct::RCTTypeFull && x.type != rct::RCTTypeSimple)
|
||||
throw boost::archive::archive_exception(boost::archive::archive_exception::other_exception, "Unsupported rct type");
|
||||
// a & x.message; message is not serialized, as it can be reconstructed from the tx data
|
||||
a & x.rangeSigs;
|
||||
if (x.type == rct::RCTTypeSimple)
|
||||
a & x.MGs;
|
||||
if (x.type == rct::RCTTypeFull)
|
||||
a & x.MG;
|
||||
// a & x.mixRing; mixRing is not serialized, as it can be reconstructed from the offsets
|
||||
if (x.type == rct::RCTTypeSimple)
|
||||
a & x.pseudoOuts;
|
||||
|
@ -264,6 +259,24 @@ namespace boost
|
|||
serializeOutPk(a, x.outPk, ver);
|
||||
a & x.txnFee;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
inline void serialize(Archive &a, rct::rctSig &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
a & x.type;
|
||||
if (x.type != rct::RCTTypeFull && x.type != rct::RCTTypeSimple)
|
||||
throw boost::archive::archive_exception(boost::archive::archive_exception::other_exception, "Unsupported rct type");
|
||||
// a & x.message; message is not serialized, as it can be reconstructed from the tx data
|
||||
// a & x.mixRing; mixRing is not serialized, as it can be reconstructed from the offsets
|
||||
if (x.type == rct::RCTTypeSimple)
|
||||
a & x.pseudoOuts;
|
||||
a & x.ecdhInfo;
|
||||
serializeOutPk(a, x.outPk, ver);
|
||||
a & x.txnFee;
|
||||
//--------------
|
||||
a & x.p.rangeSigs;
|
||||
a & x.p.MGs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace cryptonote
|
|||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
|
||||
//TODO: validate tx
|
||||
|
||||
crypto::cn_fast_hash(tx_blob.data(), tx_blob.size(), tx_hash);
|
||||
get_transaction_hash(tx, tx_hash);
|
||||
get_transaction_prefix_hash(tx, tx_prefix_hash);
|
||||
return true;
|
||||
}
|
||||
|
@ -905,20 +905,49 @@ namespace cryptonote
|
|||
crypto::hash get_transaction_hash(const transaction& t)
|
||||
{
|
||||
crypto::hash h = null_hash;
|
||||
size_t blob_size = 0;
|
||||
get_object_hash(t, h, blob_size);
|
||||
get_transaction_hash(t, h, NULL);
|
||||
return h;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res)
|
||||
{
|
||||
size_t blob_size = 0;
|
||||
return get_object_hash(t, res, blob_size);
|
||||
return get_transaction_hash(t, res, NULL);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size)
|
||||
{
|
||||
// v1 transactions hash the entire blob
|
||||
if (t.version == 1)
|
||||
{
|
||||
size_t ignored_blob_size, &blob_size_ref = blob_size ? *blob_size : ignored_blob_size;
|
||||
return get_object_hash(t, res, blob_size_ref);
|
||||
}
|
||||
|
||||
// v2 transactions hash different parts together, than hash the set of those hashes
|
||||
crypto::hash hashes[3];
|
||||
|
||||
// prefix
|
||||
get_transaction_prefix_hash(t, hashes[0]);
|
||||
|
||||
// base rct data
|
||||
get_blob_hash(t_serializable_object_to_blob((const rct::rctSigBase&)t.rct_signatures), hashes[1]);
|
||||
|
||||
// prunable rct data
|
||||
get_blob_hash(t_serializable_object_to_blob(t.rct_signatures.p), hashes[2]);
|
||||
|
||||
// the tx hash is the hash of the 3 hashes
|
||||
res = cn_fast_hash(hashes, sizeof(hashes));
|
||||
|
||||
// we still need the size
|
||||
if (blob_size)
|
||||
*blob_size = get_object_blobsize(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size)
|
||||
{
|
||||
return get_object_hash(t, res, blob_size);
|
||||
return get_transaction_hash(t, res, &blob_size);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
blobdata get_block_hashing_blob(const block& b)
|
||||
|
|
|
@ -111,6 +111,7 @@ namespace cryptonote
|
|||
crypto::hash get_transaction_hash(const transaction& t);
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res);
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size);
|
||||
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size);
|
||||
blobdata get_block_hashing_blob(const block& b);
|
||||
bool get_block_hash(const block& b, crypto::hash& res);
|
||||
crypto::hash get_block_hash(const block& b);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue