From b3d299d2413f628bdab4aa55d14bc76a71a837a8 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 21 Jul 2015 09:23:14 -0400 Subject: [PATCH] #170 Make sure accounts cannot be updated with impossible auhtority settings --- libraries/chain/account_evaluator.cpp | 1 + .../include/graphene/chain/protocol/authority.hpp | 10 +++++++++- libraries/chain/protocol/account.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index 7a6ac1fd..c7e38452 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -31,6 +31,7 @@ void_result account_create_evaluator::do_evaluate( const account_create_operatio const auto& global_props = d.get_global_properties(); const auto& chain_params = global_props.parameters; + verify_authority_accounts( op.owner ); verify_authority_accounts( op.active ); diff --git a/libraries/chain/include/graphene/chain/protocol/authority.hpp b/libraries/chain/include/graphene/chain/protocol/authority.hpp index 843a4638..f00009a6 100644 --- a/libraries/chain/include/graphene/chain/protocol/authority.hpp +++ b/libraries/chain/include/graphene/chain/protocol/authority.hpp @@ -54,6 +54,14 @@ namespace graphene { namespace chain { { account_auths[k] = w; } + bool is_impossible()const + { + uint64_t auth_weights = 0; + for( const auto& item : account_auths ) auth_weights += item.second; + for( const auto& item : key_auths ) auth_weights += item.second; + for( const auto& item : address_auths ) auth_weights += item.second; + return auth_weights < weight_threshold; + } template void add_authorities(AuthType k, weight_type w) @@ -75,7 +83,7 @@ namespace graphene { namespace chain { result.push_back(k.first); return result; } - uint32_t num_auths()const { return account_auths.size() + key_auths.size(); } + uint32_t num_auths()const { return account_auths.size() + key_auths.size() + address_auths.size(); } void clear() { account_auths.clear(); key_auths.clear(); } uint32_t weight_threshold = 0; diff --git a/libraries/chain/protocol/account.cpp b/libraries/chain/protocol/account.cpp index b1bec699..1a4726ae 100644 --- a/libraries/chain/protocol/account.cpp +++ b/libraries/chain/protocol/account.cpp @@ -141,6 +141,8 @@ void account_create_operation::validate()const FC_ASSERT( owner.address_auths.size() == 0 ); FC_ASSERT( active.num_auths() != 0 ); FC_ASSERT( active.address_auths.size() == 0 ); + FC_ASSERT( !owner.is_impossible(), "cannot create an account with an imposible owner authority threshold" ); + FC_ASSERT( !active.is_impossible(), "cannot create an account with an imposible active authority threshold" ); options.validate(); } @@ -165,11 +167,13 @@ void account_update_operation::validate()const { FC_ASSERT( owner->num_auths() != 0 ); FC_ASSERT( owner->address_auths.size() == 0 ); + FC_ASSERT( !owner->is_impossible(), "cannot update an account with an imposible owner authority threshold" ); } if( active ) { FC_ASSERT( active->num_auths() != 0 ); FC_ASSERT( active->address_auths.size() == 0 ); + FC_ASSERT( !active->is_impossible(), "cannot update an account with an imposible active authority threshold" ); } if( new_options )