From c5d908af10032efaf8d59bd4665ec5a86dfdc079 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Fri, 20 Jan 2023 10:53:40 -0300 Subject: [PATCH] Disable the creation of accounts starting with ibc, add small test --- contracts/eosio.system/src/eosio.system.cpp | 8 ++++++++ tests/telos.system_tests.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index da48cad1..62f90a39 100644 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -453,6 +453,14 @@ namespace eosiosystem { ignore owner, ignore active ) { + // BEGIN TELOS + if (!has_auth(_self)) + check( + new_account_name.to_string().find("ibc.", 0, 4) != 0, + "only eosio can create names that start with 'ibc.'" + ); + // END TELOS + if( creator != get_self() ) { uint64_t tmp = new_account_name.value >> 4; bool has_dot = false; diff --git a/tests/telos.system_tests.cpp b/tests/telos.system_tests.cpp index 0036252e..d272384e 100644 --- a/tests/telos.system_tests.cpp +++ b/tests/telos.system_tests.cpp @@ -387,4 +387,20 @@ BOOST_FIXTURE_TEST_CASE(multi_producer_pay, eosio_system_tester, * boost::unit_t } } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE( ibc_new_account, eosio_system_tester ) try { + + // fail if alice tries + BOOST_REQUIRE_EXCEPTION( + create_account_with_resources("ibc.testing"_n, "alice1111111"_n), + eosio_assert_message_exception, + eosio_assert_message_is("only eosio can create names that start with 'ibc.'") + ); + + // success if sudo account tries + BOOST_REQUIRE_EQUAL( + false, + create_account_with_resources("ibc.testing"_n, "eosio"_n)->except.has_value()); + +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_SUITE_END()