Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
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>
31
#include "
cryptonote_basic/cryptonote_basic_impl.h
"
32
#include "
cryptonote_basic/cryptonote_format_utils.h
"
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
{
44
cryptonote::transaction
tx;
45
46
if
(!
cryptonote::parse_and_validate_tx_from_blob
(tx_blob, tx))
47
{
48
MERROR
(
"Failed to parse transaction"
);
49
return
false
;
50
}
51
52
if
(
cryptonote::is_coinbase
(tx))
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
}
blockchain.h
cryptonote::Blockchain
Definition
blockchain.h:98
cryptonote::transaction_prefix::vin
std::vector< txin_v > vin
Definition
cryptonote_basic.h:263
cryptonote::transaction_prefix::version
size_t version
Definition
cryptonote_basic.h:260
cryptonote::transaction
Definition
cryptonote_basic.h:298
cryptonote_basic_impl.h
cryptonote_format_utils.h
MERROR
#define MERROR(x)
Definition
misc_log_ex.h:73
cryptonote
Holds cryptonote related classes and helpers.
Definition
ban.cpp:40
cryptonote::relative_output_offsets_to_absolute
std::vector< uint64_t > relative_output_offsets_to_absolute(const std::vector< uint64_t > &off)
Definition
cryptonote_format_utils.cpp:1230
cryptonote::tx_sanity_check
bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
Definition
tx_sanity_check.cpp:42
cryptonote::is_coinbase
bool is_coinbase(const transaction &tx)
Definition
cryptonote_basic_impl.cpp:232
cryptonote::blobdata
std::string blobdata
Definition
blobdatatype.h:39
cryptonote::parse_and_validate_tx_from_blob
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
Definition
cryptonote_format_utils.cpp:133
stdint.h
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
cryptonote::txin_to_key
Definition
cryptonote_basic.h:198
cryptonote::txin_to_key::key_offsets
std::vector< uint64_t > key_offsets
Definition
cryptonote_basic.h:200
cryptonote::txin_to_key::amount
uint64_t amount
Definition
cryptonote_basic.h:199
tx_sanity_check.h
src
cryptonote_core
tx_sanity_check.cpp
Generated on
for Electroneum by
1.17.0