Electroneum
tx_sanity_check.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #include <stdint.h>
30 #include <vector>
33 #include "blockchain.h"
34 #include "tx_sanity_check.h"
35 
36 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
37 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "verify"
38 
39 namespace cryptonote
40 {
41 
42 bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
43 {
45 
47  {
48  MERROR("Failed to parse transaction");
49  return false;
50  }
51 
53  {
54  MERROR("Transaction is coinbase");
55  return false;
56  }
57  std::set<uint64_t> rct_indices;
58  size_t n_indices = 0;
59 
60  for (const auto &txin : tx.vin)
61  {
62  if (txin.type() != typeid(cryptonote::txin_to_key))
63  continue;
64  const cryptonote::txin_to_key &in_to_key = boost::get<cryptonote::txin_to_key>(txin);
65  if (in_to_key.amount != 0)
66  continue;
67  const std::vector<uint64_t> absolute = cryptonote::relative_output_offsets_to_absolute(in_to_key.key_offsets);
68  for (uint64_t offset: absolute)
69  rct_indices.insert(offset);
70  n_indices += in_to_key.key_offsets.size();
71  }
72 
73  if (tx.version < 3 && n_indices <= 10)
74  {
75  MERROR("n_indices is only " << n_indices);
76  return true;
77  }
78 
79  return true;
80 }
81 
82 }
#define MERROR(x)
Definition: misc_log_ex.h:73
bool is_coinbase(const transaction &tx)
std::vector< uint64_t > key_offsets
std::vector< uint64_t > relative_output_offsets_to_absolute(const std::vector< uint64_t > &off)
bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
Holds cryptonote related classes and helpers.
Definition: ban.cpp:40
unsigned __int64 uint64_t
Definition: stdint.h:136
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
std::string blobdata
Definition: blobdatatype.h:39