Skip to content

Commit

Permalink
Move verify_authority to own header in prep to be templated steemit#1674
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Dec 12, 2017
1 parent 10a5b2f commit de60ba7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 102 deletions.
11 changes: 0 additions & 11 deletions libraries/protocol/include/steemit/protocol/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ namespace steemit { namespace protocol {
void clear() { operations.clear(); signatures.clear(); }
};

void verify_authority( const vector<operation>& ops, const flat_set<public_key_type>& sigs,
const authority_getter& get_active,
const authority_getter& get_owner,
const authority_getter& get_posting,
uint32_t max_recursion = STEEMIT_MAX_SIG_CHECK_DEPTH,
bool allow_committe = false,
const flat_set< account_name_type >& active_aprovals = flat_set< account_name_type >(),
const flat_set< account_name_type >& owner_aprovals = flat_set< account_name_type >(),
const flat_set< account_name_type >& posting_approvals = flat_set< account_name_type >());


struct annotated_signed_transaction : public signed_transaction {
annotated_signed_transaction(){}
annotated_signed_transaction( const signed_transaction& trx )
Expand Down
96 changes: 96 additions & 0 deletions libraries/protocol/include/steemit/protocol/transaction_util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#pragma once
#include <steemit/protocol/sign_state.hpp>
#include <steemit/protocol/exceptions.hpp>

namespace steemit { namespace protocol {

void verify_authority( const vector<operation>& ops, const flat_set<public_key_type>& sigs,
const authority_getter& get_active,
const authority_getter& get_owner,
const authority_getter& get_posting,
uint32_t max_recursion_depth = STEEMIT_MAX_SIG_CHECK_DEPTH,
bool allow_committe = false,
const flat_set< account_name_type >& active_approvals = flat_set< account_name_type >(),
const flat_set< account_name_type >& owner_approvals = flat_set< account_name_type >(),
const flat_set< account_name_type >& posting_approvals = flat_set< account_name_type >()
)
{ try {
flat_set< account_name_type > required_active;
flat_set< account_name_type > required_owner;
flat_set< account_name_type > required_posting;
vector< authority > other;

for( const auto& op : ops )
operation_get_required_authorities( op, required_active, required_owner, required_posting, other );

/**
* Transactions with operations required posting authority cannot be combined
* with transactions requiring active or owner authority. This is for ease of
* implementation. Future versions of authority verification may be able to
* check for the merged authority of active and posting.
*/
if( required_posting.size() ) {
FC_ASSERT( required_active.size() == 0 );
FC_ASSERT( required_owner.size() == 0 );
FC_ASSERT( other.size() == 0 );

flat_set< public_key_type > avail;
sign_state s(sigs,get_posting,avail);
s.max_recursion = max_recursion_depth;
for( auto& id : posting_approvals )
s.approved_by.insert( id );
for( const auto& id : required_posting )
{
STEEMIT_ASSERT( s.check_authority(id) ||
s.check_authority(get_active(id)) ||
s.check_authority(get_owner(id)),
tx_missing_posting_auth, "Missing Posting Authority ${id}",
("id",id)
("posting",get_posting(id))
("active",get_active(id))
("owner",get_owner(id)) );
}
STEEMIT_ASSERT(
!s.remove_unused_signatures(),
tx_irrelevant_sig,
"Unnecessary signature(s) detected"
);
return;
}

flat_set< public_key_type > avail;
sign_state s(sigs,get_active,avail);
s.max_recursion = max_recursion_depth;
for( auto& id : active_approvals )
s.approved_by.insert( id );
for( auto& id : owner_approvals )
s.approved_by.insert( id );

for( const auto& auth : other )
{
STEEMIT_ASSERT( s.check_authority(auth), tx_missing_other_auth, "Missing Authority", ("auth",auth)("sigs",sigs) );
}

// fetch all of the top level authorities
for( const auto& id : required_active )
{
STEEMIT_ASSERT( s.check_authority(id) ||
s.check_authority(get_owner(id)),
tx_missing_active_auth, "Missing Active Authority ${id}", ("id",id)("auth",get_active(id))("owner",get_owner(id)) );
}

for( const auto& id : required_owner )
{
STEEMIT_ASSERT( owner_approvals.find(id) != owner_approvals.end() ||
s.check_authority(get_owner(id)),
tx_missing_owner_auth, "Missing Owner Authority ${id}", ("id",id)("auth",get_owner(id)) );
}

STEEMIT_ASSERT(
!s.remove_unused_signatures(),
tx_irrelevant_sig,
"Unnecessary signature(s) detected"
);
} FC_CAPTURE_AND_RETHROW( (ops)(sigs) ) }

} } // steemit::protocol
92 changes: 1 addition & 91 deletions libraries/protocol/transaction.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <steemit/protocol/transaction.hpp>
#include <steemit/protocol/exceptions.hpp>
#include <steemit/protocol/transaction_util.hpp>

#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
Expand Down Expand Up @@ -82,96 +82,6 @@ void transaction::get_required_authorities( flat_set< account_name_type >& activ
operation_get_required_authorities( op, active, owner, posting, other );
}

void verify_authority( const vector<operation>& ops, const flat_set<public_key_type>& sigs,
const authority_getter& get_active,
const authority_getter& get_owner,
const authority_getter& get_posting,
uint32_t max_recursion_depth,
bool allow_committe,
const flat_set< account_name_type >& active_aprovals,
const flat_set< account_name_type >& owner_approvals,
const flat_set< account_name_type >& posting_approvals
)
{ try {
flat_set< account_name_type > required_active;
flat_set< account_name_type > required_owner;
flat_set< account_name_type > required_posting;
vector< authority > other;

for( const auto& op : ops )
operation_get_required_authorities( op, required_active, required_owner, required_posting, other );

/**
* Transactions with operations required posting authority cannot be combined
* with transactions requiring active or owner authority. This is for ease of
* implementation. Future versions of authority verification may be able to
* check for the merged authority of active and posting.
*/
if( required_posting.size() ) {
FC_ASSERT( required_active.size() == 0 );
FC_ASSERT( required_owner.size() == 0 );
FC_ASSERT( other.size() == 0 );

flat_set< public_key_type > avail;
sign_state s(sigs,get_posting,avail);
s.max_recursion = max_recursion_depth;
for( auto& id : posting_approvals )
s.approved_by.insert( id );
for( auto id : required_posting )
{
STEEMIT_ASSERT( s.check_authority(id) ||
s.check_authority(get_active(id)) ||
s.check_authority(get_owner(id)),
tx_missing_posting_auth, "Missing Posting Authority ${id}",
("id",id)
("posting",get_posting(id))
("active",get_active(id))
("owner",get_owner(id)) );
}
STEEMIT_ASSERT(
!s.remove_unused_signatures(),
tx_irrelevant_sig,
"Unnecessary signature(s) detected"
);
return;
}

flat_set< public_key_type > avail;
sign_state s(sigs,get_active,avail);
s.max_recursion = max_recursion_depth;
for( auto& id : active_aprovals )
s.approved_by.insert( id );
for( auto& id : owner_approvals )
s.approved_by.insert( id );

for( const auto& auth : other )
{
STEEMIT_ASSERT( s.check_authority(auth), tx_missing_other_auth, "Missing Authority", ("auth",auth)("sigs",sigs) );
}

// fetch all of the top level authorities
for( auto id : required_active )
{
STEEMIT_ASSERT( s.check_authority(id) ||
s.check_authority(get_owner(id)),
tx_missing_active_auth, "Missing Active Authority ${id}", ("id",id)("auth",get_active(id))("owner",get_owner(id)) );
}

for( auto id : required_owner )
{
STEEMIT_ASSERT( owner_approvals.find(id) != owner_approvals.end() ||
s.check_authority(get_owner(id)),
tx_missing_owner_auth, "Missing Owner Authority ${id}", ("id",id)("auth",get_owner(id)) );
}

STEEMIT_ASSERT(
!s.remove_unused_signatures(),
tx_irrelevant_sig,
"Unnecessary signature(s) detected"
);
} FC_CAPTURE_AND_RETHROW( (ops)(sigs) ) }


flat_set<public_key_type> signed_transaction::get_signature_keys( const chain_id_type& chain_id )const
{ try {
auto d = sig_digest( chain_id );
Expand Down

0 comments on commit de60ba7

Please sign in to comment.