BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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 
#define GRAPHENE_TEMP_ACCOUNT
Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) ...
Definition: config.hpp:133
std::string to_base58(const char *d, size_t s)
Definition: base58.cpp:612
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
share_type calculate_fee(const fee_parameters_type &k) const
bool verify_sum(const std::vector< commitment_type > &commits, const std::vector< commitment_type > &neg_commits, int64_t excess)
Definition: api.cpp:56
range_proof_info range_get_info(const range_proof_type &proof)
uint64_t fee
the cost to register the cheapest non-free account
#define GRAPHENE_MAX_SHARE_SUPPLY
Definition: config.hpp:38
commitment_type blind(const blind_factor_type &blind, uint64_t value)
uint64_t fee
the cost to register the cheapest non-free account
Converts blinded/stealth balance to a public account balance.
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:74
share_type calculate_fee(const fee_parameters_type &) const
std::vector< char > from_base58(const std::string &base58_str)
Definition: base58.cpp:622
asset_id_type asset_id
Definition: asset.hpp:39
Transfers from blind to blind.
Converts public account balance to a blinded or stealth balance.
T value
Definition: safe.hpp:22