Monero
Loading...
Searching...
No Matches
cryptonote_boost_serialization.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, 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// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31#pragma once
32
33#include <boost/serialization/vector.hpp>
34#include <boost/serialization/utility.hpp>
35#include <boost/serialization/variant.hpp>
36#include <boost/serialization/set.hpp>
37#include <boost/serialization/map.hpp>
38#include <boost/serialization/is_bitwise_serializable.hpp>
41#include "cryptonote_basic.h"
42#include "difficulty.h"
44#include "crypto/crypto.h"
45#include "ringct/rctTypes.h"
46#include "ringct/rctOps.h"
47
48namespace boost
49{
50 namespace serialization
51 {
52
53 //---------------------------------------------------
54 template <class Archive>
55 inline void serialize(Archive &a, crypto::public_key &x, const boost::serialization::version_type ver)
56 {
57 a & reinterpret_cast<char (&)[sizeof(crypto::public_key)]>(x);
58 }
59 template <class Archive>
60 inline void serialize(Archive &a, crypto::secret_key &x, const boost::serialization::version_type ver)
61 {
62 a & reinterpret_cast<char (&)[sizeof(crypto::secret_key)]>(x);
63 }
64 template <class Archive>
65 inline void serialize(Archive &a, crypto::key_derivation &x, const boost::serialization::version_type ver)
66 {
67 a & reinterpret_cast<char (&)[sizeof(crypto::key_derivation)]>(x);
68 }
69 template <class Archive>
70 inline void serialize(Archive &a, crypto::key_image &x, const boost::serialization::version_type ver)
71 {
72 a & reinterpret_cast<char (&)[sizeof(crypto::key_image)]>(x);
73 }
74 template <class Archive>
75 inline void serialize(Archive &a, crypto::view_tag &x, const boost::serialization::version_type ver)
76 {
77 a & reinterpret_cast<char (&)[sizeof(crypto::view_tag)]>(x);
78 }
79 template <class Archive>
80 inline void serialize(Archive &a, crypto::signature &x, const boost::serialization::version_type ver)
81 {
82 a & reinterpret_cast<char (&)[sizeof(crypto::signature)]>(x);
83 }
84 template <class Archive>
85 inline void serialize(Archive &a, crypto::hash &x, const boost::serialization::version_type ver)
86 {
87 a & reinterpret_cast<char (&)[sizeof(crypto::hash)]>(x);
88 }
89 template <class Archive>
90 inline void serialize(Archive &a, crypto::hash8 &x, const boost::serialization::version_type ver)
91 {
92 a & reinterpret_cast<char (&)[sizeof(crypto::hash8)]>(x);
93 }
94
95 template <class Archive>
96 inline void serialize(Archive &a, cryptonote::txout_to_script &x, const boost::serialization::version_type ver)
97 {
98 a & x.keys;
99 a & x.script;
100 }
101
102
103 template <class Archive>
104 inline void serialize(Archive &a, cryptonote::txout_to_key &x, const boost::serialization::version_type ver)
105 {
106 a & x.key;
107 }
108
109 template <class Archive>
110 inline void serialize(Archive &a, cryptonote::txout_to_tagged_key &x, const boost::serialization::version_type ver)
111 {
112 a & x.key;
113 a & x.view_tag;
114 }
115
116 template <class Archive>
117 inline void serialize(Archive &a, cryptonote::txout_to_scripthash &x, const boost::serialization::version_type ver)
118 {
119 a & x.hash;
120 }
121
122 template <class Archive>
123 inline void serialize(Archive &a, cryptonote::txin_gen &x, const boost::serialization::version_type ver)
124 {
125 a & x.height;
126 }
127
128 template <class Archive>
129 inline void serialize(Archive &a, cryptonote::txin_to_script &x, const boost::serialization::version_type ver)
130 {
131 a & x.prev;
132 a & x.prevout;
133 a & x.sigset;
134 }
135
136 template <class Archive>
137 inline void serialize(Archive &a, cryptonote::txin_to_scripthash &x, const boost::serialization::version_type ver)
138 {
139 a & x.prev;
140 a & x.prevout;
141 a & x.script;
142 a & x.sigset;
143 }
144
145 template <class Archive>
146 inline void serialize(Archive &a, cryptonote::txin_to_key &x, const boost::serialization::version_type ver)
147 {
148 a & x.amount;
149 a & x.key_offsets;
150 a & x.k_image;
151 }
152
153 template <class Archive>
154 inline void serialize(Archive &a, cryptonote::tx_out &x, const boost::serialization::version_type ver)
155 {
156 a & x.amount;
157 a & x.target;
158 }
159
160
161 template <class Archive>
162 inline void serialize(Archive &a, cryptonote::transaction_prefix &x, const boost::serialization::version_type ver)
163 {
164 a & x.version;
165 a & x.unlock_time;
166 a & x.vin;
167 a & x.vout;
168 a & x.extra;
169 }
170
171 template <class Archive>
172 inline void serialize(Archive &a, cryptonote::transaction &x, const boost::serialization::version_type ver)
173 {
174 a & x.version;
175 a & x.unlock_time;
176 a & x.vin;
177 a & x.vout;
178 a & x.extra;
179 if (x.version == 1)
180 {
181 a & x.signatures;
182 }
183 else
184 {
187 a & x.rct_signatures.p;
188 }
189 }
190
191 template <class Archive>
192 inline void serialize(Archive &a, cryptonote::block &b, const boost::serialization::version_type ver)
193 {
194 a & b.major_version;
195 a & b.minor_version;
196 a & b.timestamp;
197 a & b.prev_id;
198 a & b.nonce;
199 //------------------
200 a & b.miner_tx;
201 a & b.tx_hashes;
202 }
203
204 template <class Archive>
205 inline void serialize(Archive &a, rct::key &x, const boost::serialization::version_type ver)
206 {
207 a & reinterpret_cast<char (&)[sizeof(rct::key)]>(x);
208 }
209
210 template <class Archive>
211 inline void serialize(Archive &a, rct::ctkey &x, const boost::serialization::version_type ver)
212 {
213 a & x.dest;
214 a & x.mask;
215 }
216
217 template <class Archive>
218 inline void serialize(Archive &a, rct::rangeSig &x, const boost::serialization::version_type ver)
219 {
220 a & x.asig;
221 a & x.Ci;
222 }
223
224 template <class Archive>
225 inline void serialize(Archive &a, rct::Bulletproof &x, const boost::serialization::version_type ver)
226 {
227 a & x.V;
228 a & x.A;
229 a & x.S;
230 a & x.T1;
231 a & x.T2;
232 a & x.taux;
233 a & x.mu;
234 a & x.L;
235 a & x.R;
236 a & x.a;
237 a & x.b;
238 a & x.t;
239 }
240
241 template <class Archive>
242 inline void serialize(Archive &a, rct::BulletproofPlus &x, const boost::serialization::version_type ver)
243 {
244 a & x.V;
245 a & x.A;
246 a & x.A1;
247 a & x.B;
248 a & x.r1;
249 a & x.s1;
250 a & x.d1;
251 a & x.L;
252 a & x.R;
253 }
254
255 template <class Archive>
256 inline void serialize(Archive &a, rct::boroSig &x, const boost::serialization::version_type ver)
257 {
258 a & x.s0;
259 a & x.s1;
260 a & x.ee;
261 }
262
263 template <class Archive>
264 inline void serialize(Archive &a, rct::mgSig &x, const boost::serialization::version_type ver)
265 {
266 a & x.ss;
267 a & x.cc;
268 // a & x.II; // not serialized, we can recover it from the tx vin
269 }
270
271 template <class Archive>
272 inline void serialize(Archive &a, rct::clsag &x, const boost::serialization::version_type ver)
273 {
274 a & x.s;
275 a & x.c1;
276 // a & x.I; // not serialized, we can recover it from the tx vin
277 a & x.D;
278 }
279
280 template <class Archive>
281 inline void serialize(Archive &a, rct::ecdhTuple &x, const boost::serialization::version_type ver)
282 {
283 a & x.mask;
284 a & x.amount;
285 }
286
287 template <class Archive>
288 inline void serialize(Archive &a, rct::multisig_kLRki &x, const boost::serialization::version_type ver)
289 {
290 a & x.k;
291 a & x.L;
292 a & x.R;
293 a & x.ki;
294 }
295
296 template <class Archive>
297 inline void serialize(Archive &a, rct::multisig_out &x, const boost::serialization::version_type ver)
298 {
299 a & x.c;
300 if (ver < 1)
301 return;
302 a & x.mu_p;
303 }
304
305 template <class Archive>
306 inline typename std::enable_if<Archive::is_loading::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
307 {
308 rct::keyV outPk;
309 a & outPk;
310 outPk_.resize(outPk.size());
311 for (size_t n = 0; n < outPk_.size(); ++n)
312 {
313 outPk_[n].dest = rct::identity();
314 outPk_[n].mask = outPk[n];
315 }
316 }
317
318 template <class Archive>
319 inline typename std::enable_if<Archive::is_saving::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
320 {
321 rct::keyV outPk(outPk_.size());
322 for (size_t n = 0; n < outPk_.size(); ++n)
323 outPk[n] = outPk_[n].mask;
324 a & outPk;
325 }
326
327 template <class Archive>
328 inline void serialize(Archive &a, rct::rctSigBase &x, const boost::serialization::version_type ver)
329 {
330 a & x.type;
331 if (x.type == rct::RCTTypeNull)
332 return;
334 throw boost::archive::archive_exception(boost::archive::archive_exception::other_exception, "Unsupported rct type");
335 // a & x.message; message is not serialized, as it can be reconstructed from the tx data
336 // a & x.mixRing; mixRing is not serialized, as it can be reconstructed from the offsets
337 if (x.type == rct::RCTTypeSimple) // moved to prunable with bulletproofs
338 a & x.pseudoOuts;
339 a & x.ecdhInfo;
340 serializeOutPk(a, x.outPk, ver);
341 a & x.txnFee;
342 }
343
344 template <class Archive>
345 inline void serialize(Archive &a, rct::rctSigPrunable &x, const boost::serialization::version_type ver)
346 {
347 a & x.rangeSigs;
348 if (x.rangeSigs.empty())
349 {
350 a & x.bulletproofs;
351 if (ver >= 2u)
353 }
354 a & x.MGs;
355 if (ver >= 1u)
356 a & x.CLSAGs;
357 if (x.rangeSigs.empty())
358 a & x.pseudoOuts;
359 }
360
361 template <class Archive>
362 inline void serialize(Archive &a, rct::rctSig &x, const boost::serialization::version_type ver)
363 {
364 a & x.type;
365 if (x.type == rct::RCTTypeNull)
366 return;
368 throw boost::archive::archive_exception(boost::archive::archive_exception::other_exception, "Unsupported rct type");
369 // a & x.message; message is not serialized, as it can be reconstructed from the tx data
370 // a & x.mixRing; mixRing is not serialized, as it can be reconstructed from the offsets
371 if (x.type == rct::RCTTypeSimple)
372 a & x.pseudoOuts;
373 a & x.ecdhInfo;
374 serializeOutPk(a, x.outPk, ver);
375 a & x.txnFee;
376 //--------------
377 a & x.p.rangeSigs;
378 if (x.p.rangeSigs.empty())
379 {
380 a & x.p.bulletproofs;
381 if (ver >= 2u)
383 }
384 a & x.p.MGs;
385 if (ver >= 1u)
386 a & x.p.CLSAGs;
388 a & x.p.pseudoOuts;
389 }
390
391 template <class Archive>
392 inline void serialize(Archive &a, rct::RCTConfig &x, const boost::serialization::version_type ver)
393 {
395 a & x.bp_version;
396 }
397
398 template <class Archive>
399 inline void serialize(Archive &a, cryptonote::difficulty_type &x, const boost::serialization::version_type ver)
400 {
401 if (Archive::is_loading::value)
402 {
403 // load high part
404 uint64_t v = 0;
405 a & v;
406 x = v;
407 // load low part
408 x = x << 64;
409 a & v;
410 x += v;
411 }
412 else
413 {
414 // store high part
415 cryptonote::difficulty_type x_ = (x >> 64) & 0xffffffffffffffff;
416 uint64_t v = x_.convert_to<uint64_t>();
417 a & v;
418 // store low part
419 x_ = x & 0xffffffffffffffff;
420 v = x_.convert_to<uint64_t>();
421 a & v;
422 }
423 }
424
425}
426}
427
429BOOST_CLASS_VERSION(rct::rctSig, 2)
430BOOST_CLASS_VERSION(rct::multisig_out, 1)
cryptonote::block b
Definition block.cpp:40
Definition cryptonote_basic.h:171
std::vector< uint8_t > extra
Definition cryptonote_basic.h:181
std::vector< txin_v > vin
Definition cryptonote_basic.h:178
size_t version
Definition cryptonote_basic.h:175
std::vector< tx_out > vout
Definition cryptonote_basic.h:179
uint64_t unlock_time
Definition cryptonote_basic.h:176
Definition cryptonote_basic.h:205
rct::rctSig rct_signatures
Definition cryptonote_basic.h:214
std::vector< std::vector< crypto::signature > > signatures
Definition cryptonote_basic.h:213
Definition unordered_containers_boost_serialization.h:40
void serialize(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
Definition unordered_containers_boost_serialization.h:126
std::enable_if< Archive::is_loading::value, void >::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
Definition cryptonote_boost_serialization.h:306
Definition portable_binary_archive.hpp:29
POD_CLASS signature
Definition crypto.h:98
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:72
POD_CLASS hash8
Definition hash.h:52
POD_CLASS key_derivation
Definition crypto.h:91
POD_CLASS view_tag
Definition crypto.h:103
POD_CLASS public_key
Definition crypto.h:64
POD_CLASS key_image
Definition crypto.h:95
POD_CLASS hash
Definition hash.h:49
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:41
Definition bulletproofs.cc:64
std::vector< key > keyV
Definition rctTypes.h:89
std::vector< ctkey > ctkeyV
Definition rctTypes.h:109
@ RCTTypeFull
Definition rctTypes.h:300
@ RCTTypeSimple
Definition rctTypes.h:301
@ RCTTypeCLSAG
Definition rctTypes.h:304
@ RCTTypeBulletproof2
Definition rctTypes.h:303
@ RCTTypeBulletproof
Definition rctTypes.h:302
@ RCTTypeNull
Definition rctTypes.h:299
@ RCTTypeBulletproofPlus
Definition rctTypes.h:305
key identity()
Definition rctOps.h:73
BOOST_CLASS_VERSION(nodetool::peerlist_types, nodetool::CURRENT_PEERLIST_STORAGE_ARCHIVE_VER)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
unsigned __int64 uint64_t
Definition stdint.h:136
Definition cryptonote_basic.h:475
Definition cryptonote_basic.h:158
txout_target_v target
Definition cryptonote_basic.h:160
uint64_t amount
Definition cryptonote_basic.h:159
Definition cryptonote_basic.h:102
size_t height
Definition cryptonote_basic.h:103
Definition cryptonote_basic.h:139
crypto::key_image k_image
Definition cryptonote_basic.h:142
std::vector< uint64_t > key_offsets
Definition cryptonote_basic.h:141
uint64_t amount
Definition cryptonote_basic.h:140
Definition cryptonote_basic.h:111
crypto::hash prev
Definition cryptonote_basic.h:112
std::vector< uint8_t > sigset
Definition cryptonote_basic.h:114
size_t prevout
Definition cryptonote_basic.h:113
Definition cryptonote_basic.h:124
size_t prevout
Definition cryptonote_basic.h:126
std::vector< uint8_t > sigset
Definition cryptonote_basic.h:128
txout_to_script script
Definition cryptonote_basic.h:127
crypto::hash prev
Definition cryptonote_basic.h:125
Definition cryptonote_basic.h:79
crypto::public_key key
Definition cryptonote_basic.h:82
Definition cryptonote_basic.h:62
std::vector< crypto::public_key > keys
Definition cryptonote_basic.h:63
std::vector< uint8_t > script
Definition cryptonote_basic.h:64
Definition cryptonote_basic.h:73
crypto::hash hash
Definition cryptonote_basic.h:74
Definition cryptonote_basic.h:87
crypto::public_key key
Definition cryptonote_basic.h:90
crypto::view_tag view_tag
Definition cryptonote_basic.h:91
Definition rctTypes.h:250
rct::keyV L
Definition rctTypes.h:254
rct::key B
Definition rctTypes.h:252
rct::key A
Definition rctTypes.h:252
rct::key r1
Definition rctTypes.h:253
rct::keyV R
Definition rctTypes.h:254
rct::key s1
Definition rctTypes.h:253
rct::keyV V
Definition rctTypes.h:251
rct::key A1
Definition rctTypes.h:252
rct::key d1
Definition rctTypes.h:253
Definition rctTypes.h:213
rct::key T2
Definition rctTypes.h:215
rct::key t
Definition rctTypes.h:218
rct::key T1
Definition rctTypes.h:215
rct::key S
Definition rctTypes.h:215
rct::key a
Definition rctTypes.h:218
rct::keyV L
Definition rctTypes.h:217
rct::key taux
Definition rctTypes.h:216
rct::keyV V
Definition rctTypes.h:214
rct::keyV R
Definition rctTypes.h:217
rct::key b
Definition rctTypes.h:218
rct::key A
Definition rctTypes.h:215
rct::key mu
Definition rctTypes.h:216
Definition rctTypes.h:308
int bp_version
Definition rctTypes.h:310
RangeProofType range_proof_type
Definition rctTypes.h:309
Definition rctTypes.h:155
key64 s1
Definition rctTypes.h:157
key ee
Definition rctTypes.h:158
key64 s0
Definition rctTypes.h:156
Definition rctTypes.h:181
key D
Definition rctTypes.h:186
key c1
Definition rctTypes.h:183
keyV s
Definition rctTypes.h:182
Definition rctTypes.h:97
key dest
Definition rctTypes.h:98
key mask
Definition rctTypes.h:99
Definition rctTypes.h:140
key amount
Definition rctTypes.h:142
key mask
Definition rctTypes.h:141
Definition rctTypes.h:79
Definition rctTypes.h:168
keyM ss
Definition rctTypes.h:169
key cc
Definition rctTypes.h:170
Definition rctTypes.h:113
key ki
Definition rctTypes.h:117
key L
Definition rctTypes.h:115
key k
Definition rctTypes.h:114
key R
Definition rctTypes.h:116
Definition rctTypes.h:122
std::vector< key > c
Definition rctTypes.h:123
std::vector< key > mu_p
Definition rctTypes.h:124
Definition rctTypes.h:202
boroSig asig
Definition rctTypes.h:203
key64 Ci
Definition rctTypes.h:204
Definition rctTypes.h:318
xmr_amount txnFee
Definition rctTypes.h:326
std::vector< ecdhTuple > ecdhInfo
Definition rctTypes.h:324
uint8_t type
Definition rctTypes.h:319
keyV pseudoOuts
Definition rctTypes.h:323
ctkeyV outPk
Definition rctTypes.h:325
Definition rctTypes.h:416
std::vector< clsag > CLSAGs
Definition rctTypes.h:421
keyV pseudoOuts
Definition rctTypes.h:422
std::vector< mgSig > MGs
Definition rctTypes.h:420
std::vector< BulletproofPlus > bulletproofs_plus
Definition rctTypes.h:419
std::vector< rangeSig > rangeSigs
Definition rctTypes.h:417
std::vector< Bulletproof > bulletproofs
Definition rctTypes.h:418
Definition rctTypes.h:613
rctSigPrunable p
Definition rctTypes.h:614