BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
confidential.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
26 
27 #include <fc/crypto/base58.hpp>
28 #include <fc/io/raw.hpp>
29 
30 namespace graphene { namespace protocol {
31 
33 {
34  FC_ASSERT( fee.amount >= 0 );
35  FC_ASSERT( amount.amount > 0 );
36 
37  vector<commitment_type> in;
38  vector<commitment_type> out(outputs.size());
39  int64_t net_public = amount.amount.value;
40  for( uint32_t i = 0; i < out.size(); ++i )
41  {
42  out[i] = outputs[i].commitment;
45  if( i > 0 ) FC_ASSERT( out[i-1] < out[i], "all outputs must be sorted by commitment id" );
46  FC_ASSERT( !outputs[i].owner.is_impossible() );
47  }
48  FC_ASSERT( out.size(), "there must be at least one output" );
49 
50  auto public_c = fc::ecc::blind(blinding_factor,net_public);
51 
52  FC_ASSERT( fc::ecc::verify_sum( {public_c}, out, 0 ), "", ("net_public",net_public) );
53 
54  if( outputs.size() > 1 )
55  {
56  for( auto out : outputs )
57  {
58  auto info = fc::ecc::range_get_info( out.range_proof );
59  FC_ASSERT( info.max_value <= GRAPHENE_MAX_SHARE_SUPPLY );
60  }
61  }
62 }
63 
65 {
66  return k.fee + outputs.size() * k.price_per_output;
67 }
68 
69 
71 {
72  FC_ASSERT( amount.amount > 0 );
73  FC_ASSERT( fee.amount >= 0 );
74  FC_ASSERT( inputs.size() > 0 );
76 
77 
78  vector<commitment_type> in(inputs.size());
79  vector<commitment_type> out;
80  int64_t net_public = fee.amount.value + amount.amount.value;
81  out.push_back( fc::ecc::blind( blinding_factor, net_public ) );
82  for( uint32_t i = 0; i < in.size(); ++i )
83  {
84  in[i] = inputs[i].commitment;
86  if( i > 0 ) FC_ASSERT( in[i-1] < in[i], "all inputs must be sorted by commitment id" );
87  }
88  FC_ASSERT( in.size(), "there must be at least one input" );
89  FC_ASSERT( fc::ecc::verify_sum( in, out, 0 ) );
90 }
91 
92 
98 {
99  return GRAPHENE_TEMP_ACCOUNT;
100 }
101 
102 
107 { try {
108  vector<commitment_type> in(inputs.size());
109  vector<commitment_type> out(outputs.size());
110  int64_t net_public = fee.amount.value;//from_amount.value - to_amount.value;
111  for( uint32_t i = 0; i < in.size(); ++i )
112  {
113  in[i] = inputs[i].commitment;
115  if( i > 0 ) FC_ASSERT( in[i-1] < in[i] );
116  }
117  for( uint32_t i = 0; i < out.size(); ++i )
118  {
119  out[i] = outputs[i].commitment;
120  if( i > 0 ) FC_ASSERT( out[i-1] < out[i] );
121  FC_ASSERT( !outputs[i].owner.is_impossible() );
122  }
123  FC_ASSERT( in.size(), "there must be at least one input" );
124  FC_ASSERT( fc::ecc::verify_sum( in, out, net_public ), "", ("net_public", net_public) );
125 
126  if( outputs.size() > 1 )
127  {
128  for( auto out : outputs )
129  {
130  auto info = fc::ecc::range_get_info( out.range_proof );
131  FC_ASSERT( info.max_value <= GRAPHENE_MAX_SHARE_SUPPLY );
132  }
133  }
134  FC_ASSERT( fc::ecc::verify_sum( in, out, net_public ), "", ("net_public", net_public) );
135 } FC_CAPTURE_AND_RETHROW( (*this) ) }
136 
138 {
139  return k.fee + outputs.size() * k.price_per_output;
140 }
141 
145 stealth_confirmation::operator string()const
146 {
147  return fc::to_base58( fc::raw::pack( *this ) );
148 }
152 stealth_confirmation::stealth_confirmation( const std::string& base58 )
153 {
154  *this = fc::raw::unpack<stealth_confirmation>( fc::from_base58( base58 ) );
155 }
156 
157 } } // graphene::protocol
158 
GRAPHENE_MAX_SHARE_SUPPLY
constexpr int64_t GRAPHENE_MAX_SHARE_SUPPLY(1000000000000000LL)
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::protocol::transfer_from_blind_operation::fee_params_t
Definition: confidential.hpp:175
graphene::protocol::transfer_to_blind_operation
Converts public account balance to a blinded or stealth balance.
Definition: confidential.hpp:150
fc::to_base58
std::string to_base58(const char *d, size_t s)
Definition: base58.cpp:612
graphene::protocol::blind_transfer_operation
Transfers from blind to blind.
Definition: confidential.hpp:238
graphene::protocol::transfer_to_blind_operation::fee
asset fee
Definition: confidential.hpp:158
graphene::protocol::transfer_from_blind_operation::inputs
vector< blind_input > inputs
Definition: confidential.hpp:183
graphene::protocol::transfer_to_blind_operation::fee_params_t::price_per_output
uint32_t price_per_output
Definition: confidential.hpp:154
fc::ecc::blind
commitment_type blind(const blind_factor_type &blind, uint64_t value)
Definition: elliptic_secp256k1.cpp:208
graphene::protocol::blind_transfer_operation::fee_params_t
Definition: confidential.hpp:240
graphene::protocol::blind_transfer_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k) const
Definition: confidential.cpp:137
GRAPHENE_TEMP_ACCOUNT
#define GRAPHENE_TEMP_ACCOUNT
Represents the canonical account with WILDCARD authority (anybody can access funds in temp account)
Definition: config.hpp:148
fc::from_base58
std::vector< char > from_base58(const std::string &base58_str)
Definition: base58.cpp:622
graphene::protocol::blind_transfer_operation::outputs
vector< blind_output > outputs
Definition: confidential.hpp:247
graphene::protocol::transfer_from_blind_operation::blinding_factor
blind_factor_type blinding_factor
Definition: confidential.hpp:182
graphene::protocol::transfer_to_blind_operation::fee_params_t
Definition: confidential.hpp:152
graphene::protocol::blind_transfer_operation::validate
void validate() const
Definition: confidential.cpp:106
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:86
graphene::protocol::blind_transfer_operation::fee_payer
account_id_type fee_payer() const
Definition: confidential.cpp:97
fc::ecc::range_get_info
range_proof_info range_get_info(const range_proof_type &proof)
Definition: elliptic_secp256k1.cpp:291
graphene::protocol::transfer_to_blind_operation::validate
void validate() const
Definition: confidential.cpp:32
graphene::protocol::transfer_from_blind_operation
Converts blinded/stealth balance to a public account balance.
Definition: confidential.hpp:173
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
confidential.hpp
graphene::protocol::blind_transfer_operation::inputs
vector< blind_input > inputs
Definition: confidential.hpp:246
graphene::protocol::stealth_confirmation::stealth_confirmation
stealth_confirmation()
Definition: confidential.hpp:121
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
base58.hpp
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::protocol::blind_transfer_operation::fee_params_t::fee
uint64_t fee
the cost to register the cheapest non-free account
Definition: confidential.hpp:241
graphene::protocol::blind_transfer_operation::fee
asset fee
Definition: confidential.hpp:245
graphene::protocol::transfer_to_blind_operation::calculate_fee
share_type calculate_fee(const fee_params_t &) const
Definition: confidential.cpp:64
graphene::protocol::transfer_from_blind_operation::validate
void validate() const
Definition: confidential.cpp:70
fc::safe::value
T value
Definition: safe.hpp:28
graphene::protocol::transfer_to_blind_operation::blinding_factor
blind_factor_type blinding_factor
Definition: confidential.hpp:161
graphene::protocol::transfer_to_blind_operation::outputs
vector< blind_output > outputs
Definition: confidential.hpp:162
graphene::protocol::transfer_from_blind_operation::fee
asset fee
Definition: confidential.hpp:179
graphene::protocol::transfer_to_blind_operation::fee_params_t::fee
uint64_t fee
the cost to register the cheapest non-free account
Definition: confidential.hpp:153
fc::ecc::verify_sum
bool verify_sum(const std::vector< commitment_type > &commits, const std::vector< commitment_type > &neg_commits, int64_t excess)
Definition: elliptic_secp256k1.cpp:225
graphene::protocol::blind_transfer_operation::fee_params_t::price_per_output
uint32_t price_per_output
Definition: confidential.hpp:242
graphene::protocol::transfer_from_blind_operation::amount
asset amount
Definition: confidential.hpp:180
graphene
Definition: api.cpp:48
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
graphene::protocol::transfer_to_blind_operation::amount
asset amount
Definition: confidential.hpp:159
raw.hpp
fc::safe
Definition: safe.hpp:26