aboutsummaryrefslogtreecommitdiffhomepage
path: root/tde2e
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2025-04-11 13:31:29 +0400
committerArseny Smirnov <arseny30@gmail.com>2025-04-11 13:31:29 +0400
commit7dfe60f100f4d840dca4faf71991da2f918ed2d4 (patch)
treeccca1f95cf6a1d245336e27c915a2e5e6362387e /tde2e
parentaefd7826f762e03b1375f6c60b23d642d67d0210 (diff)
e2e: return error it client tries to resuse the same private key for different calls
Diffstat (limited to 'tde2e')
-rw-r--r--tde2e/td/e2e/Call.cpp9
-rw-r--r--tde2e/td/e2e/e2e_errors.h5
-rw-r--r--tde2e/test/e2e.cpp1
3 files changed, 14 insertions, 1 deletions
diff --git a/tde2e/td/e2e/Call.cpp b/tde2e/td/e2e/Call.cpp
index c467329c8..dca0e3459 100644
--- a/tde2e/td/e2e/Call.cpp
+++ b/tde2e/td/e2e/Call.cpp
@@ -571,6 +571,15 @@ td::Result<std::string> Call::create_self_add_block(const PrivateKey &private_ke
}
td::Result<Call> Call::create(td::int64 user_id, PrivateKey private_key, td::Slice last_block_server) {
+ {
+ // Forbid creating multiple calls with the same key
+ static std::mutex mutex;
+ static td::FlatHashSet<td::UInt256, UInt256Hash> public_keys;
+ std::lock_guard<std::mutex> lock(mutex);
+ if (!public_keys.insert(private_key.to_public_key().to_u256()).second) {
+ return Error(E::CallKeyAlreadyUsed);
+ }
+ }
TRY_RESULT(last_block, Blockchain::from_server_to_local(last_block_server.str()));
TRY_RESULT(blockchain, ClientBlockchain::create_from_block(last_block, private_key.to_public_key()));
auto call = Call(user_id, std::move(private_key), std::move(blockchain));
diff --git a/tde2e/td/e2e/e2e_errors.h b/tde2e/td/e2e/e2e_errors.h
index 686311418..d1168ef18 100644
--- a/tde2e/td/e2e/e2e_errors.h
+++ b/tde2e/td/e2e/e2e_errors.h
@@ -37,7 +37,8 @@ enum class ErrorCode : int {
InvalidBroadcast_InvalidReveal = 505,
InvalidBroadcast_InvalidBlockHash = 506,
InvalidCallChannelId = 600,
- CallFailed = 601
+ CallFailed = 601,
+ CallKeyAlreadyUsed = 602
};
inline std::string_view error_string(ErrorCode error_code) {
switch (error_code) {
@@ -93,6 +94,8 @@ inline std::string_view error_string(ErrorCode error_code) {
return "INVALID_BROADCAST__INVALID_BLOCK_HASH";
case ErrorCode::CallFailed:
return "CALL_FAILED";
+ case ErrorCode::CallKeyAlreadyUsed:
+ return "CALL_KEY_ALREADY_USED";
case ErrorCode::InvalidCallChannelId:
return "INVALID_CALL_CHANNEL_ID";
}
diff --git a/tde2e/test/e2e.cpp b/tde2e/test/e2e.cpp
index 6ad625d06..808a776f7 100644
--- a/tde2e/test/e2e.cpp
+++ b/tde2e/test/e2e.cpp
@@ -736,6 +736,7 @@ TEST(Call, Basic_API) {
auto zero_block = F(call_create_zero_block(key0, CallState{0, {CallParticipant{-1, pkey0, 3}}})).value();
auto call1 = call_create(-1, key0, zero_block).value();
+ ASSERT_TRUE(!call_create(-1, key0, zero_block).is_ok());
auto block0 = F(call_create_self_add_block(key1, zero_block, CallParticipant{1, pkey1, 3})).value();
call1 = call_create(1, key1, block0).value();