From a4dcd51e03ac1073c5d245707b0f1bbd0dc7d9ee Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 10 Aug 2017 10:12:39 -0500 Subject: [PATCH 1/4] Ref #66: Add issue number to TODO --- libraries/chain/include/eos/chain/authority_checker.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/eos/chain/authority_checker.hpp b/libraries/chain/include/eos/chain/authority_checker.hpp index dca8b39a1d3..3e655850e96 100644 --- a/libraries/chain/include/eos/chain/authority_checker.hpp +++ b/libraries/chain/include/eos/chain/authority_checker.hpp @@ -68,7 +68,7 @@ class AuthorityChecker { return totalWeight; } UInt32 operator()(const types::AccountPermissionWeight& permission) { - //TODO: Recursion limit? Yes: implement as producer-configurable parameter + //TODO #66: Recursion limit? Yes: implement as producer-configurable parameter if (checker.satisfied(permission.permission)) totalWeight += permission.weight; return totalWeight; From 1c91f3efe6c167a774535539b84e261e9a5d7bc0 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 10 Aug 2017 11:17:34 -0500 Subject: [PATCH 2/4] Add one more test on AuthorityChecker --- tests/tests/misc_tests.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/tests/misc_tests.cpp b/tests/tests/misc_tests.cpp index a3e5b6d458a..b482ba00e99 100644 --- a/tests/tests/misc_tests.cpp +++ b/tests/tests/misc_tests.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -241,6 +242,18 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK_EQUAL(checker.used_keys().count(b), 1); BOOST_CHECK_EQUAL(checker.used_keys().count(c), 1); } + + A = Complex_Authority(2, ((a, 1))((b, 1))((c, 1)),); + auto B = Complex_Authority(1, ((b, 1))((c, 1)),); + { + auto checker = MakeAuthorityChecker(GetNullAuthority, {a,b,c}); + BOOST_CHECK(validate(A)); + BOOST_CHECK(validate(B)); + BOOST_CHECK(checker.satisfied(A)); + BOOST_CHECK(checker.satisfied(B)); + BOOST_CHECK(!checker.all_keys_used()); + BOOST_CHECK_EQUAL(checker.unused_keys().count(c), 1); + } } FC_LOG_AND_RETHROW() } /// Test creating the wallet From 19c1a3e81a31a88691332b3e5b4cfa8d19d07920 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 10 Aug 2017 12:23:52 -0500 Subject: [PATCH 3/4] Add missing test --- tests/tests/misc_tests.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tests/misc_tests.cpp b/tests/tests/misc_tests.cpp index b482ba00e99..631b0ce2b52 100644 --- a/tests/tests/misc_tests.cpp +++ b/tests/tests/misc_tests.cpp @@ -223,6 +223,11 @@ BOOST_AUTO_TEST_CASE(authority_checker) }; A = Complex_Authority(5, ((a, 2))((b, 2))((c, 2)), (("top", "top", 5))); + { + auto checker = MakeAuthorityChecker(GetAuthority, {d, e}); + BOOST_CHECK(checker.satisfied(A)); + BOOST_CHECK(checker.all_keys_used()); + } { auto checker = MakeAuthorityChecker(GetAuthority, {a,b,c,d,e}); BOOST_CHECK(checker.satisfied(A)); From 543a68764abf40707338efd362adb89dc67080ff Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 10 Aug 2017 12:18:23 -0500 Subject: [PATCH 4/4] Resolve #66: Add authority recursion depth limit We now enforce a recursion depth limit for authority checks. If the limit is hit, it silently rejects the authority. --- libraries/chain/chain_controller.cpp | 4 +- .../include/eos/chain/authority_checker.hpp | 30 +++--- libraries/chain/include/eos/chain/config.hpp | 2 + .../eos/native_contract/genesis_state.hpp | 3 +- libraries/types/types.eos | 1 + tests/common/database_fixture.cpp | 3 +- tests/tests/misc_tests.cpp | 93 ++++++++++--------- tests/tests/native_contract_tests.cpp | 92 +++++++++--------- 8 files changed, 123 insertions(+), 105 deletions(-) diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index ffff7d970b3..3b5adeae55b 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -485,6 +485,7 @@ void chain_controller::check_transaction_authorization(const SignedTransaction& return; } + auto getPermission = [&db=_db](const types::AccountPermission& permission) { auto key = boost::make_tuple(permission.account, permission.permission); return db.get(key); @@ -492,8 +493,9 @@ void chain_controller::check_transaction_authorization(const SignedTransaction& auto getAuthority = [&getPermission](const types::AccountPermission& permission) { return getPermission(permission).auth; }; + auto depthLimit = get_global_properties().configuration.authDepthLimit; #warning TODO: Use a real chain_id here (where is this stored? Do we still need it?) - auto checker = MakeAuthorityChecker(std::move(getAuthority), trx.get_signature_keys(chain_id_type{})); + auto checker = MakeAuthorityChecker(std::move(getAuthority), depthLimit, trx.get_signature_keys(chain_id_type{})); for (const auto& message : trx.messages) for (const auto& declaredAuthority : message.authorization) { diff --git a/libraries/chain/include/eos/chain/authority_checker.hpp b/libraries/chain/include/eos/chain/authority_checker.hpp index 3e655850e96..8afef75a172 100644 --- a/libraries/chain/include/eos/chain/authority_checker.hpp +++ b/libraries/chain/include/eos/chain/authority_checker.hpp @@ -47,6 +47,7 @@ using MetaPermissionSet = boost::container::flat_multiset class AuthorityChecker { F PermissionToAuthority; + UInt16 recursionDepthLimit; vector signingKeys; vector usedKeys; @@ -54,10 +55,11 @@ class AuthorityChecker { using result_type = UInt32; AuthorityChecker& checker; + UInt16 recursionDepth; UInt32 totalWeight = 0; - WeightTallyVisitor(AuthorityChecker& checker) - : checker(checker) {} + WeightTallyVisitor(AuthorityChecker& checker, UInt16 recursionDepth) + : checker(checker), recursionDepth(recursionDepth) {} UInt32 operator()(const types::KeyPermissionWeight& permission) { auto itr = boost::find(checker.signingKeys, permission.key); @@ -68,25 +70,30 @@ class AuthorityChecker { return totalWeight; } UInt32 operator()(const types::AccountPermissionWeight& permission) { - //TODO #66: Recursion limit? Yes: implement as producer-configurable parameter - if (checker.satisfied(permission.permission)) + if (recursionDepth < checker.recursionDepthLimit + && checker.satisfied(permission.permission, recursionDepth + 1)) totalWeight += permission.weight; return totalWeight; } }; public: - AuthorityChecker(F PermissionToAuthority, const flat_set& signingKeys) + AuthorityChecker(F PermissionToAuthority, UInt16 recursionDepthLimit, const flat_set& signingKeys) : PermissionToAuthority(PermissionToAuthority), + recursionDepthLimit(recursionDepthLimit), signingKeys(signingKeys.begin(), signingKeys.end()), usedKeys(signingKeys.size(), false) {} - bool satisfied(const types::AccountPermission& permission) { - return satisfied(PermissionToAuthority(permission)); + bool satisfied(const types::AccountPermission& permission, UInt16 depth = 0) { + return satisfied(PermissionToAuthority(permission), depth); } template - bool satisfied(const AuthorityType& authority) { + bool satisfied(const AuthorityType& authority, UInt16 depth = 0) { + // This check is redundant, since WeightTallyVisitor did it too, but I'll leave it here for future-proofing + if (depth > recursionDepthLimit) + return false; + // Save the current used keys; if we do not satisfy this authority, the newly used keys aren't actually used auto KeyReverter = fc::make_scoped_exit([this, keys = usedKeys] () mutable { usedKeys = keys; @@ -98,7 +105,7 @@ class AuthorityChecker { permissions.insert(authority.accounts.begin(), authority.accounts.end()); // Check all permissions, from highest weight to lowest, seeing if signingKeys satisfies them or not - WeightTallyVisitor visitor(*this); + WeightTallyVisitor visitor(*this, depth); for (const auto& permission : permissions) // If we've got enough weight, to satisfy the authority, return! if (permission.visit(visitor) >= authority.threshold) { @@ -120,8 +127,9 @@ class AuthorityChecker { }; template -AuthorityChecker MakeAuthorityChecker(F&& pta, const flat_set& signingKeys) { - return AuthorityChecker(std::forward(pta), signingKeys); +AuthorityChecker MakeAuthorityChecker(F&& pta, UInt16 recursionDepthLimit, + const flat_set& signingKeys) { + return AuthorityChecker(std::forward(pta), recursionDepthLimit, signingKeys); } }} // namespace eos::chain diff --git a/libraries/chain/include/eos/chain/config.hpp b/libraries/chain/include/eos/chain/config.hpp index 5c85cbbcc1a..0e19361e499 100644 --- a/libraries/chain/include/eos/chain/config.hpp +++ b/libraries/chain/include/eos/chain/config.hpp @@ -25,6 +25,7 @@ #include namespace eos { namespace config { +using types::UInt16; using types::UInt32; using types::UInt64; using types::UInt128; @@ -59,6 +60,7 @@ const static ShareType DefaultElectedPay = Asset(100).amount; const static ShareType DefaultRunnerUpPay = Asset(75).amount; const static ShareType DefaultMinEosBalance = Asset(100).amount; const static UInt32 DefaultMaxTrxLifetime = 60*60; +const static UInt16 DefaultAuthDepthLimit = 6; const static UInt32 ProducersAuthorityThreshold = 14; const static int BlocksPerRound = 21; diff --git a/libraries/native_contract/include/eos/native_contract/genesis_state.hpp b/libraries/native_contract/include/eos/native_contract/genesis_state.hpp index 54c7adf2fee..7e65d12e4b5 100644 --- a/libraries/native_contract/include/eos/native_contract/genesis_state.hpp +++ b/libraries/native_contract/include/eos/native_contract/genesis_state.hpp @@ -75,7 +75,8 @@ struct genesis_state_type { config::DefaultElectedPay, config::DefaultRunnerUpPay, config::DefaultMinEosBalance, - config::DefaultMaxTrxLifetime + config::DefaultMaxTrxLifetime, + config::DefaultAuthDepthLimit }; vector initial_accounts; vector initial_producers; diff --git a/libraries/types/types.eos b/libraries/types/types.eos index d60ff179458..e9ab6d370c0 100644 --- a/libraries/types/types.eos +++ b/libraries/types/types.eos @@ -47,6 +47,7 @@ struct BlockchainConfiguration runnerUpPay ShareType minEosBalance ShareType maxTrxLifetime UInt32 + authDepthLimit UInt16 struct TypeDef newTypeName TypeName diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index a1e25be44f3..8e35f06e158 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -171,7 +171,8 @@ void testing_blockchain::sign_transaction(SignedTransaction& trx) { auto key = boost::make_tuple(permission.account, permission.permission); return db.get(key).auth; }; - auto checker = MakeAuthorityChecker(GetAuthority, fixture.available_keys()); + auto checker = MakeAuthorityChecker(GetAuthority, get_global_properties().configuration.authDepthLimit, + fixture.available_keys()); for (const auto& message : trx.messages) for (const auto& authorization : message.authorization) diff --git a/tests/tests/misc_tests.cpp b/tests/tests/misc_tests.cpp index 631b0ce2b52..984e4c5ca75 100644 --- a/tests/tests/misc_tests.cpp +++ b/tests/tests/misc_tests.cpp @@ -21,28 +21,28 @@ BOOST_AUTO_TEST_SUITE(misc_tests) BOOST_AUTO_TEST_CASE(median_properties_test) { try { vector votes{ - {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 }, - {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 }, - {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 }, - {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 }, - {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 }, + {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 , 6}, + {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 , 6}, + {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 , 6}, + {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 , 6}, + {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 , 6}, }; BlockchainConfiguration medians{ - 1024, 512, 1024, Asset(5000).amount, Asset(2000).amount, Asset(100).amount, 512 + 1024, 512, 1024, Asset(5000).amount, Asset(2000).amount, Asset(100).amount, 512, 6 }; BOOST_CHECK_EQUAL(BlockchainConfiguration::get_median_values(votes), medians); - votes.emplace_back(BlockchainConfiguration{1, 1, 1, 1, 1, 1, 1}); - votes.emplace_back(BlockchainConfiguration{1, 1, 1, 1, 1, 1, 1}); - medians = BlockchainConfiguration {1024, 100, 1000, Asset(3333).amount, Asset(50).amount, Asset(50).amount, 100}; + votes.emplace_back(BlockchainConfiguration{1, 1, 1, 1, 1, 1, 1, 1}); + votes.emplace_back(BlockchainConfiguration{1, 1, 1, 1, 1, 1, 1, 1}); + medians = BlockchainConfiguration {1024, 100, 1000, Asset(3333).amount, Asset(50).amount, Asset(50).amount, 100, 6}; BOOST_CHECK_EQUAL(BlockchainConfiguration::get_median_values(votes), medians); BOOST_CHECK_EQUAL(BlockchainConfiguration::get_median_values({medians}), medians); votes.erase(votes.begin() + 2); votes.erase(votes.end() - 1); - medians = BlockchainConfiguration {1024, 100, 1024, Asset(3333).amount, Asset(50).amount, Asset(100).amount, 100}; + medians = BlockchainConfiguration {1024, 100, 1024, Asset(3333).amount, Asset(50).amount, Asset(100).amount, 100, 6}; BOOST_CHECK_EQUAL(BlockchainConfiguration::get_median_values(votes), medians); } FC_LOG_AND_RETHROW() } @@ -93,21 +93,21 @@ BOOST_AUTO_TEST_CASE(authority_checker) auto A = Complex_Authority(2, ((a,1))((b,1)),); { - auto checker = MakeAuthorityChecker(GetNullAuthority, {a, b}); + auto checker = MakeAuthorityChecker(GetNullAuthority, 2, {a, b}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 2); BOOST_CHECK_EQUAL(checker.unused_keys().size(), 0); } { - auto checker = MakeAuthorityChecker(GetNullAuthority, {a, c}); + auto checker = MakeAuthorityChecker(GetNullAuthority, 2, {a, c}); BOOST_CHECK(!checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 0); BOOST_CHECK_EQUAL(checker.unused_keys().size(), 2); } { - auto checker = MakeAuthorityChecker(GetNullAuthority, {a, b, c}); + auto checker = MakeAuthorityChecker(GetNullAuthority, 2, {a, b, c}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 2); @@ -117,52 +117,52 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK_EQUAL(checker.unused_keys().count(c), 1); } { - auto checker = MakeAuthorityChecker(GetNullAuthority, {b, c}); + auto checker = MakeAuthorityChecker(GetNullAuthority, 2, {b, c}); BOOST_CHECK(!checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 0); } A = Complex_Authority(3, ((a,1))((b,1))((c,1)),); - BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, {c, b, a}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, {a, b}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, {a, c}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, {b, c}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, 2, {c, b, a}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, 2, {a, b}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, 2, {a, c}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, 2, {b, c}).satisfied(A)); A = Complex_Authority(1, ((a, 1))((b, 1)),); - BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, {a}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, {b}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, {c}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, 2, {a}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, 2, {b}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, 2, {c}).satisfied(A)); A = Complex_Authority(1, ((a, 2))((b, 1)),); - BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, {a}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, {b}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, {c}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, 2, {a}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetNullAuthority, 2, {b}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetNullAuthority, 2, {c}).satisfied(A)); auto GetCAuthority = [c_public_key](auto){return Complex_Authority(1, ((c, 1)),);}; A = Complex_Authority(2, ((a, 2))((b, 1)), (("hello", "world", 1))); { - auto checker = MakeAuthorityChecker(GetCAuthority, {a}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {a}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(checker.all_keys_used()); } { - auto checker = MakeAuthorityChecker(GetCAuthority, {b}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {b}); BOOST_CHECK(!checker.satisfied(A)); BOOST_CHECK_EQUAL(checker.used_keys().size(), 0); BOOST_CHECK_EQUAL(checker.unused_keys().size(), 1); BOOST_CHECK_EQUAL(checker.unused_keys().count(b), 1); } { - auto checker = MakeAuthorityChecker(GetCAuthority, {c}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {c}); BOOST_CHECK(!checker.satisfied(A)); BOOST_CHECK_EQUAL(checker.used_keys().size(), 0); BOOST_CHECK_EQUAL(checker.unused_keys().size(), 1); BOOST_CHECK_EQUAL(checker.unused_keys().count(c), 1); } { - auto checker = MakeAuthorityChecker(GetCAuthority, {b,c}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {b,c}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 2); @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK_EQUAL(checker.used_keys().count(c), 1); } { - auto checker = MakeAuthorityChecker(GetCAuthority, {b,c,a}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {b,c,a}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 1); @@ -182,14 +182,14 @@ BOOST_AUTO_TEST_CASE(authority_checker) } A = Complex_Authority(2, ((a, 1))((b, 1)), (("hello", "world", 1))); - BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {a}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {b}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {c}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, {a,b}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, {b,c}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, {a,c}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, 2, {a}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, 2, {b}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, 2, {c}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, 2, {a,b}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, 2, {b,c}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, 2, {a,c}).satisfied(A)); { - auto checker = MakeAuthorityChecker(GetCAuthority, {a,b,c}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {a,b,c}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 2); @@ -198,12 +198,12 @@ BOOST_AUTO_TEST_CASE(authority_checker) } A = Complex_Authority(2, ((a, 1))((b, 1)), (("hello", "world", 2))); - BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, {a,b}).satisfied(A)); - BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, {c}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {a}).satisfied(A)); - BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, {b}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, 2, {a,b}).satisfied(A)); + BOOST_CHECK(MakeAuthorityChecker(GetCAuthority, 2, {c}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, 2, {a}).satisfied(A)); + BOOST_CHECK(!MakeAuthorityChecker(GetCAuthority, 2, {b}).satisfied(A)); { - auto checker = MakeAuthorityChecker(GetCAuthority, {a,b,c}); + auto checker = MakeAuthorityChecker(GetCAuthority, 2, {a,b,c}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 1); @@ -224,12 +224,12 @@ BOOST_AUTO_TEST_CASE(authority_checker) A = Complex_Authority(5, ((a, 2))((b, 2))((c, 2)), (("top", "top", 5))); { - auto checker = MakeAuthorityChecker(GetAuthority, {d, e}); + auto checker = MakeAuthorityChecker(GetAuthority, 2, {d, e}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(checker.all_keys_used()); } { - auto checker = MakeAuthorityChecker(GetAuthority, {a,b,c,d,e}); + auto checker = MakeAuthorityChecker(GetAuthority, 2, {a,b,c,d,e}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 2); @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK_EQUAL(checker.used_keys().count(e), 1); } { - auto checker = MakeAuthorityChecker(GetAuthority, {a,b,c,e}); + auto checker = MakeAuthorityChecker(GetAuthority, 2, {a,b,c,e}); BOOST_CHECK(checker.satisfied(A)); BOOST_CHECK(!checker.all_keys_used()); BOOST_CHECK_EQUAL(checker.used_keys().size(), 3); @@ -247,11 +247,14 @@ BOOST_AUTO_TEST_CASE(authority_checker) BOOST_CHECK_EQUAL(checker.used_keys().count(b), 1); BOOST_CHECK_EQUAL(checker.used_keys().count(c), 1); } + BOOST_CHECK(MakeAuthorityChecker(GetAuthority, 1, {a,b,c}).satisfied(A)); + // Fails due to short recursion depth limit + BOOST_CHECK(!MakeAuthorityChecker(GetAuthority, 1, {d,e}).satisfied(A)); A = Complex_Authority(2, ((a, 1))((b, 1))((c, 1)),); auto B = Complex_Authority(1, ((b, 1))((c, 1)),); { - auto checker = MakeAuthorityChecker(GetNullAuthority, {a,b,c}); + auto checker = MakeAuthorityChecker(GetNullAuthority, 2, {a,b,c}); BOOST_CHECK(validate(A)); BOOST_CHECK(validate(B)); BOOST_CHECK(checker.satisfied(A)); diff --git a/tests/tests/native_contract_tests.cpp b/tests/tests/native_contract_tests.cpp index fda3b9585d4..67acc728617 100644 --- a/tests/tests/native_contract_tests.cpp +++ b/tests/tests/native_contract_tests.cpp @@ -151,30 +151,30 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters, testing_fixture) chain.produce_blocks(21); vector votes{ - {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 }, - {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 }, - {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 }, - {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 }, - {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 }, - {420 , 400 , 2710 , Asset(27599 ).amount, Asset(1177 ).amount, Asset(27720).amount, 400 }, - {271 , 200 , 66629 , Asset(2666 ).amount, Asset(99991 ).amount, Asset(277 ).amount, 200 }, - {1057 , 1000 , 2770 , Asset(972 ).amount, Asset(302716 ).amount, Asset(578 ).amount, 1000 }, - {9926 , 27 , 990 , Asset(99999 ).amount, Asset(39651 ).amount, Asset(4402 ).amount, 27 }, - {1005 , 1000 , 1917 , Asset(937111 ).amount, Asset(2734 ).amount, Asset(1 ).amount, 1000 }, - {80 , 70 , 5726 , Asset(63920 ).amount, Asset(231561 ).amount, Asset(27100).amount, 70 }, - {471617, 333333, 100 , Asset(2666 ).amount, Asset(2650 ).amount, Asset(2772 ).amount, 333333}, - {2222 , 1000 , 100 , Asset(33619 ).amount, Asset(1046 ).amount, Asset(10577).amount, 1000 }, - {8 , 7 , 100 , Asset(5757267).amount, Asset(2257 ).amount, Asset(2888 ).amount, 7 }, - {2717 , 2000 , 57797 , Asset(3366 ).amount, Asset(205 ).amount, Asset(4472 ).amount, 2000 }, - {9997 , 5000 , 27700 , Asset(29199 ).amount, Asset(100 ).amount, Asset(221 ).amount, 5000 }, - {163900, 200 , 882 , Asset(100 ).amount, Asset(5720233).amount, Asset(105 ).amount, 200 }, - {728 , 80 , 27100 , Asset(28888 ).amount, Asset(6205 ).amount, Asset(5011 ).amount, 80 }, - {91937 , 44444 , 652589, Asset(87612 ).amount, Asset(123 ).amount, Asset(2044 ).amount, 44444 }, - {171 , 96 , 123456, Asset(8402 ).amount, Asset(321 ).amount, Asset(816 ).amount, 96 }, - {17177 , 6767 , 654321, Asset(9926 ).amount, Asset(9264 ).amount, Asset(8196 ).amount, 6767 }, + {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 , 6}, + {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 , 6}, + {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 , 6}, + {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 , 6}, + {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 , 6}, + {420 , 400 , 2710 , Asset(27599 ).amount, Asset(1177 ).amount, Asset(27720).amount, 400 , 6}, + {271 , 200 , 66629 , Asset(2666 ).amount, Asset(99991 ).amount, Asset(277 ).amount, 200 , 6}, + {1057 , 1000 , 2770 , Asset(972 ).amount, Asset(302716 ).amount, Asset(578 ).amount, 1000 , 6}, + {9926 , 27 , 990 , Asset(99999 ).amount, Asset(39651 ).amount, Asset(4402 ).amount, 27 , 6}, + {1005 , 1000 , 1917 , Asset(937111 ).amount, Asset(2734 ).amount, Asset(1 ).amount, 1000 , 6}, + {80 , 70 , 5726 , Asset(63920 ).amount, Asset(231561 ).amount, Asset(27100).amount, 70 , 6}, + {471617, 333333, 100 , Asset(2666 ).amount, Asset(2650 ).amount, Asset(2772 ).amount, 33333 , 6}, + {2222 , 1000 , 100 , Asset(33619 ).amount, Asset(1046 ).amount, Asset(10577).amount, 1000 , 6}, + {8 , 7 , 100 , Asset(5757267).amount, Asset(2257 ).amount, Asset(2888 ).amount, 7 , 6}, + {2717 , 2000 , 57797 , Asset(3366 ).amount, Asset(205 ).amount, Asset(4472 ).amount, 2000 , 6}, + {9997 , 5000 , 27700 , Asset(29199 ).amount, Asset(100 ).amount, Asset(221 ).amount, 5000 , 6}, + {163900, 200 , 882 , Asset(100 ).amount, Asset(5720233).amount, Asset(105 ).amount, 200 , 6}, + {728 , 80 , 27100 , Asset(28888 ).amount, Asset(6205 ).amount, Asset(5011 ).amount, 80 , 6}, + {91937 , 44444 , 652589, Asset(87612 ).amount, Asset(123 ).amount, Asset(2044 ).amount, 44444 , 6}, + {171 , 96 , 123456, Asset(8402 ).amount, Asset(321 ).amount, Asset(816 ).amount, 96 , 6}, + {17177 , 6767 , 654321, Asset(9926 ).amount, Asset(9264 ).amount, Asset(8196 ).amount, 6767 , 6}, }; BlockchainConfiguration medians = - {1057, 512, 2770, Asset(9926).amount, Asset(2650).amount, Asset(816).amount, 512}; + {1057, 512, 2770, Asset(9926).amount, Asset(2650).amount, Asset(816).amount, 512, 6}; // If this fails, the medians variable probably needs to be updated to have the medians of the votes above BOOST_REQUIRE_EQUAL(BlockchainConfiguration::get_median_values(votes), medians); @@ -197,30 +197,30 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters_2, testing_fixture) chain.produce_blocks(21); vector votes{ - {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 }, - {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 }, - {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 }, - {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 }, - {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 }, - {420 , 400 , 2710 , Asset(27599 ).amount, Asset(1177 ).amount, Asset(27720).amount, 400 }, - {271 , 200 , 66629 , Asset(2666 ).amount, Asset(99991 ).amount, Asset(277 ).amount, 200 }, - {1057 , 1000 , 2770 , Asset(972 ).amount, Asset(302716 ).amount, Asset(578 ).amount, 1000 }, - {9926 , 27 , 990 , Asset(99999 ).amount, Asset(39651 ).amount, Asset(4402 ).amount, 27 }, - {1005 , 1000 , 1917 , Asset(937111 ).amount, Asset(2734 ).amount, Asset(1 ).amount, 1000 }, - {80 , 70 , 5726 , Asset(63920 ).amount, Asset(231561 ).amount, Asset(27100).amount, 70 }, - {471617, 333333, 100 , Asset(2666 ).amount, Asset(2650 ).amount, Asset(2772 ).amount, 333333}, - {2222 , 1000 , 100 , Asset(33619 ).amount, Asset(1046 ).amount, Asset(10577).amount, 1000 }, - {8 , 7 , 100 , Asset(5757267).amount, Asset(2257 ).amount, Asset(2888 ).amount, 7 }, - {2717 , 2000 , 57797 , Asset(3366 ).amount, Asset(205 ).amount, Asset(4472 ).amount, 2000 }, - {9997 , 5000 , 27700 , Asset(29199 ).amount, Asset(100 ).amount, Asset(221 ).amount, 5000 }, - {163900, 200 , 882 , Asset(100 ).amount, Asset(5720233).amount, Asset(105 ).amount, 200 }, - {728 , 80 , 27100 , Asset(28888 ).amount, Asset(6205 ).amount, Asset(5011 ).amount, 80 }, - {91937 , 44444 , 652589, Asset(87612 ).amount, Asset(123 ).amount, Asset(2044 ).amount, 44444 }, - {171 , 96 , 123456, Asset(8402 ).amount, Asset(321 ).amount, Asset(816 ).amount, 96 }, - {17177 , 6767 , 654321, Asset(9926 ).amount, Asset(9264 ).amount, Asset(8196 ).amount, 6767 }, + {1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 , 6}, + {10000 , 100 , 4096 , Asset(3333 ).amount, Asset(27109 ).amount, Asset(10 ).amount, 100 , 6}, + {2048 , 1500 , 1000 , Asset(5432 ).amount, Asset(2000 ).amount, Asset(50 ).amount, 1500 , 6}, + {100 , 25 , 1024 , Asset(90000 ).amount, Asset(0 ).amount, Asset(433 ).amount, 25 , 6}, + {1024 , 1000 , 100 , Asset(10 ).amount, Asset(50 ).amount, Asset(200 ).amount, 1000 , 6}, + {420 , 400 , 2710 , Asset(27599 ).amount, Asset(1177 ).amount, Asset(27720).amount, 400 , 6}, + {271 , 200 , 66629 , Asset(2666 ).amount, Asset(99991 ).amount, Asset(277 ).amount, 200 , 6}, + {1057 , 1000 , 2770 , Asset(972 ).amount, Asset(302716 ).amount, Asset(578 ).amount, 1000 , 6}, + {9926 , 27 , 990 , Asset(99999 ).amount, Asset(39651 ).amount, Asset(4402 ).amount, 27 , 6}, + {1005 , 1000 , 1917 , Asset(937111 ).amount, Asset(2734 ).amount, Asset(1 ).amount, 1000 , 6}, + {80 , 70 , 5726 , Asset(63920 ).amount, Asset(231561 ).amount, Asset(27100).amount, 70 , 6}, + {471617, 333333, 100 , Asset(2666 ).amount, Asset(2650 ).amount, Asset(2772 ).amount, 333333 , 6}, + {2222 , 1000 , 100 , Asset(33619 ).amount, Asset(1046 ).amount, Asset(10577).amount, 1000 , 6}, + {8 , 7 , 100 , Asset(5757267).amount, Asset(2257 ).amount, Asset(2888 ).amount, 7 , 6}, + {2717 , 2000 , 57797 , Asset(3366 ).amount, Asset(205 ).amount, Asset(4472 ).amount, 2000 , 6}, + {9997 , 5000 , 27700 , Asset(29199 ).amount, Asset(100 ).amount, Asset(221 ).amount, 5000 , 6}, + {163900, 200 , 882 , Asset(100 ).amount, Asset(5720233).amount, Asset(105 ).amount, 200 , 6}, + {728 , 80 , 27100 , Asset(28888 ).amount, Asset(6205 ).amount, Asset(5011 ).amount, 80 , 6}, + {91937 , 44444 , 652589, Asset(87612 ).amount, Asset(123 ).amount, Asset(2044 ).amount, 44444 , 6}, + {171 , 96 , 123456, Asset(8402 ).amount, Asset(321 ).amount, Asset(816 ).amount, 96 , 6}, + {17177 , 6767 , 654321, Asset(9926 ).amount, Asset(9264 ).amount, Asset(8196 ).amount, 6767 , 6}, }; BlockchainConfiguration medians = - {1057, 512, 2770, Asset(9926).amount, Asset(2650).amount, Asset(816).amount, 512}; + {1057, 512, 2770, Asset(9926).amount, Asset(2650).amount, Asset(816).amount, 512, 6}; // If this fails, the medians variable probably needs to be updated to have the medians of the votes above BOOST_REQUIRE_EQUAL(BlockchainConfiguration::get_median_values(votes), medians); @@ -441,8 +441,8 @@ BOOST_FIXTURE_TEST_CASE(auth_tests, testing_fixture) { // Abort if this gets run; it shouldn't get run in this test auto PermissionToAuthority = [](auto)->Authority{abort();}; - auto tradingChecker = MakeAuthorityChecker(PermissionToAuthority, {k1_public_key}); - auto spendingChecker = MakeAuthorityChecker(PermissionToAuthority, {k2_public_key}); + auto tradingChecker = MakeAuthorityChecker(PermissionToAuthority, 2, {k1_public_key}); + auto spendingChecker = MakeAuthorityChecker(PermissionToAuthority, 2, {k2_public_key}); BOOST_CHECK(tradingChecker.satisfied(trading->auth)); BOOST_CHECK(spendingChecker.satisfied(spending->auth));