BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
confidential_evaluator.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  */
30 #include <graphene/chain/hardfork.hpp>
31 
32 namespace graphene { namespace chain {
33 
35 { try {
36  const auto& d = db();
37 
38  const auto& atype = o.amount.asset_id(db());
39  FC_ASSERT( atype.allow_confidential() );
40  FC_ASSERT( !atype.is_transfer_restricted() );
41  FC_ASSERT( !(atype.options.flags & white_list) );
42 
43  for( const auto& out : o.outputs )
44  {
45  for( const auto& a : out.owner.account_auths )
46  a.first(d); // verify all accounts exist and are valid
47  }
48  return void_result();
49 } FC_CAPTURE_AND_RETHROW( (o) ) }
50 
51 
53 { try {
54  db().adjust_balance( o.from, -o.amount );
55 
56  const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
57  db().modify( add, [&]( asset_dynamic_data_object& obj ){
59  FC_ASSERT( obj.confidential_supply >= 0 );
60  });
61  for( const auto& out : o.outputs )
62  {
64  obj.asset_id = o.amount.asset_id;
65  obj.owner = out.owner;
66  obj.commitment = out.commitment;
67  });
68  }
69  return void_result();
70 } FC_CAPTURE_AND_RETHROW( (o) ) }
71 
73 {
74  if( db().head_block_time() >= HARDFORK_563_TIME )
76  else
78 }
79 
81 { try {
82  const auto& d = db();
83  o.fee.asset_id(d); // verify fee is a legit asset
84  const auto& bbi = d.get_index_type<blinded_balance_index>();
85  const auto& cidx = bbi.indices().get<by_commitment>();
86  for( const auto& in : o.inputs )
87  {
88  auto itr = cidx.find( in.commitment );
89  FC_ASSERT( itr != cidx.end() );
90  FC_ASSERT( itr->asset_id == o.fee.asset_id );
91  FC_ASSERT( itr->owner == in.owner );
92  }
93  return void_result();
94 } FC_CAPTURE_AND_RETHROW( (o) ) }
95 
97 { try {
98  db().adjust_balance( o.fee_payer(), o.fee );
99  db().adjust_balance( o.to, o.amount );
100  const auto& bbi = db().get_index_type<blinded_balance_index>();
101  const auto& cidx = bbi.indices().get<by_commitment>();
102  for( const auto& in : o.inputs )
103  {
104  auto itr = cidx.find( in.commitment );
105  FC_ASSERT( itr != cidx.end() );
106  db().remove( *itr );
107  }
108  const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
109  db().modify( add, [&]( asset_dynamic_data_object& obj ){
111  FC_ASSERT( obj.confidential_supply >= 0 );
112  });
113  return void_result();
114 } FC_CAPTURE_AND_RETHROW( (o) ) }
115 
117 {
118  if( db().head_block_time() >= HARDFORK_563_TIME )
120  else
122 }
123 
125 { try {
126  const auto& d = db();
127  o.fee.asset_id(db()); // verify fee is a legit asset
128  const auto& bbi = db().get_index_type<blinded_balance_index>();
129  const auto& cidx = bbi.indices().get<by_commitment>();
130  for( const auto& out : o.outputs )
131  {
132  for( const auto& a : out.owner.account_auths )
133  a.first(d); // verify all accounts exist and are valid
134  }
135  for( const auto& in : o.inputs )
136  {
137  auto itr = cidx.find( in.commitment );
138  GRAPHENE_ASSERT( itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment",in.commitment) );
139  FC_ASSERT( itr->asset_id == o.fee.asset_id );
140  FC_ASSERT( itr->owner == in.owner );
141  }
142  return void_result();
143 } FC_CAPTURE_AND_RETHROW( (o) ) }
144 
146 { try {
147  db().adjust_balance( o.fee_payer(), o.fee ); // deposit the fee to the temp account
148  const auto& bbi = db().get_index_type<blinded_balance_index>();
149  const auto& cidx = bbi.indices().get<by_commitment>();
150  for( const auto& in : o.inputs )
151  {
152  auto itr = cidx.find( in.commitment );
153  GRAPHENE_ASSERT( itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment",in.commitment) );
154  db().remove( *itr );
155  }
156  for( const auto& out : o.outputs )
157  {
159  obj.asset_id = o.fee.asset_id;
160  obj.owner = out.owner;
161  obj.commitment = out.commitment;
162  });
163  }
164  const auto& add = o.fee.asset_id(db()).dynamic_asset_data_id(db());
165  db().modify( add, [&]( asset_dynamic_data_object& obj ){
166  obj.confidential_supply -= o.fee.amount;
167  FC_ASSERT( obj.confidential_supply >= 0 );
168  });
169 
170  return void_result();
171 } FC_CAPTURE_AND_RETHROW( (o) ) }
172 
174 {
175  if( db().head_block_time() >= HARDFORK_563_TIME )
177  else
179 }
180 
181 } } // graphene::chain
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::protocol::transfer_to_blind_operation
Converts public account balance to a blinded or stealth balance.
Definition: confidential.hpp:150
fba_accumulator_id.hpp
graphene::chain::transfer_to_blind_evaluator::do_evaluate
void_result do_evaluate(const transfer_to_blind_operation &o)
Definition: confidential_evaluator.cpp:34
graphene::protocol::blind_transfer_operation
Transfers from blind to blind.
Definition: confidential.hpp:238
graphene::chain::transfer_to_blind_evaluator::pay_fee
virtual void pay_fee() override
Definition: confidential_evaluator.cpp:72
graphene::chain::blind_transfer_evaluator::do_evaluate
void_result do_evaluate(const blind_transfer_operation &o)
Definition: confidential_evaluator.cpp:124
graphene::chain::transfer_from_blind_evaluator::do_apply
void_result do_apply(const transfer_from_blind_operation &o)
Definition: confidential_evaluator.cpp:96
graphene::protocol::transfer_from_blind_operation::inputs
vector< blind_input > inputs
Definition: confidential.hpp:183
database.hpp
graphene::protocol::transfer_from_blind_operation::to
account_id_type to
Definition: confidential.hpp:181
graphene::protocol::blind_transfer_operation::outputs
vector< blind_output > outputs
Definition: confidential.hpp:247
graphene::db::object_database::create
const T & create(F &&constructor)
Definition: object_database.hpp:63
graphene::chain::database::adjust_balance
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account's balance in a given asset by a delta.
Definition: db_balance.cpp:54
graphene::chain::asset_dynamic_data_object::confidential_supply
share_type confidential_supply
total asset held in confidential balances
Definition: asset_object.hpp:62
graphene::chain::generic_evaluator::pay_fee
virtual void pay_fee()
Definition: evaluator.cpp:91
graphene::chain::blind_transfer_evaluator::do_apply
void_result do_apply(const blind_transfer_operation &o)
Definition: confidential_evaluator.cpp:145
graphene::protocol::white_list
@ white_list
accounts must be whitelisted in order to hold or transact this asset
Definition: types.hpp:195
graphene::protocol::blind_transfer_operation::fee_payer
account_id_type fee_payer() const
Definition: confidential.cpp:97
graphene::protocol::transfer_from_blind_operation::fee_payer
account_id_type fee_payer() const
Definition: confidential.hpp:185
graphene::chain::generic_evaluator::pay_fba_fee
void pay_fba_fee(uint64_t fba_id)
Definition: evaluator.cpp:100
graphene::protocol::transfer_from_blind_operation
Converts blinded/stealth balance to a public account balance.
Definition: confidential.hpp:173
graphene::db::generic_index::find
const object * find(object_id_type id) const override
Definition: generic_index.hpp:98
graphene::db::generic_index::indices
const index_type & indices() const
Definition: generic_index.hpp:115
graphene::chain::asset_dynamic_data_object
tracks the asset information that changes frequently
Definition: asset_object.hpp:56
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
confidential.hpp
graphene::chain::fba_accumulator_id_transfer_to_blind
@ fba_accumulator_id_transfer_to_blind
Definition: fba_accumulator_id.hpp:35
graphene::protocol::blind_transfer_operation::inputs
vector< blind_input > inputs
Definition: confidential.hpp:246
graphene::chain::blinded_balance_object
tracks a blinded balance commitment
Definition: confidential_object.hpp:41
graphene::protocol::transfer_to_blind_operation::from
account_id_type from
Definition: confidential.hpp:160
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
graphene::chain::transfer_from_blind_evaluator::do_evaluate
void_result do_evaluate(const transfer_from_blind_operation &o)
Definition: confidential_evaluator.cpp:80
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::chain::fba_accumulator_id_blind_transfer
@ fba_accumulator_id_blind_transfer
Definition: fba_accumulator_id.hpp:36
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::chain::fba_accumulator_id_transfer_from_blind
@ fba_accumulator_id_transfer_from_blind
Definition: fba_accumulator_id.hpp:37
confidential_object.hpp
graphene::chain::transfer_from_blind_evaluator::pay_fee
virtual void pay_fee() override
Definition: confidential_evaluator.cpp:116
graphene::db::generic_index
Definition: generic_index.hpp:43
confidential_evaluator.hpp
graphene::protocol::blind_transfer_operation::fee
asset fee
Definition: confidential.hpp:245
graphene::chain::transfer_to_blind_evaluator::do_apply
void_result do_apply(const transfer_to_blind_operation &o)
Definition: confidential_evaluator.cpp:52
GRAPHENE_ASSERT
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
graphene::protocol::void_result
Definition: base.hpp:86
graphene::db::object_database::remove
void remove(const object &obj)
Definition: object_database.hpp:97
graphene::db::object_database::get_index_type
const IndexType & get_index_type() const
Definition: object_database.hpp:77
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_from_blind_operation::amount
asset amount
Definition: confidential.hpp:180
graphene
Definition: api.cpp:48
exceptions.hpp
graphene::db::object_database::modify
void modify(const T &obj, const Lambda &m)
Definition: object_database.hpp:99
graphene::chain::blind_transfer_evaluator::pay_fee
virtual void pay_fee() override
Definition: confidential_evaluator.cpp:173
graphene::protocol::transfer_to_blind_operation::amount
asset amount
Definition: confidential.hpp:159