SKALE-3951 add tests, update VERSION

parent f423edba
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "SGXWalletServer.hpp" #include "SGXWalletServer.hpp"
#include "catch.hpp" #include "catch.hpp"
#include "zmq_src/ZMQClient.h"
#include "BLSSigShare.h" #include "BLSSigShare.h"
#include "BLSSigShareSet.h" #include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h" #include "BLSPublicKeyShare.h"
...@@ -396,42 +395,40 @@ void TestUtils::sendRPCRequestV2() { ...@@ -396,42 +395,40 @@ void TestUtils::sendRPCRequestV2() {
} }
void TestUtils::sendRPCRequestZMQ() { void TestUtils::sendRPCRequestZMQ() {
HttpClient client(RPC_ENDPOINT); auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
StubClient c(client, JSONRPC_CLIENT_V2); "./sgx_data/cert_data/rootCA.key");
int n = 16, t = 16; int n = 16, t = 16;
Json::Value ethKeys[n]; vector<string> ethKeys(n);
Json::Value verifVects[n]; Json::Value verifVects[n];
Json::Value pubEthKeys; Json::Value pubEthKeys;
Json::Value secretShares[n]; vector<string> secretShares(n);
Json::Value pubBLSKeys[n]; Json::Value pubBLSKeys[n];
Json::Value blsSigShares[n]; vector<string> blsSigShares(n);
vector <string> pubShares(n); vector<string> pubShares(n);
vector <string> polyNames(n); vector<string> polyNames(n);
static atomic<int> counter(1); static atomic<int> counter(1);
int schainID = counter.fetch_add(1); int schainID = counter.fetch_add(1);
int dkgID = counter.fetch_add(1); int dkgID = counter.fetch_add(1);
for (uint8_t i = 0; i < n; i++) { for (uint8_t i = 0; i < n; i++) {
ethKeys[i] = c.generateECDSAKey(); auto generatedKey = client->generateECDSAKey();
CHECK_STATE(ethKeys[i]["status"] == 0); ethKeys[i] = generatedKey.second;
string polyName = string polyName =
"POLY:SCHAIN_ID:" + to_string(schainID) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkgID); "POLY:SCHAIN_ID:" + to_string(schainID) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkgID);
auto response = c.generateDKGPoly(polyName, t); CHECK_STATE(client->generateDKGPoly(polyName, t));
CHECK_STATE(response["status"] == 0);
polyNames[i] = polyName; polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t); verifVects[i] = client->getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
pubEthKeys.append(ethKeys[i]["publicKey"]); pubEthKeys.append(generatedKey.first);
} }
for (uint8_t i = 0; i < n; i++) { for (uint8_t i = 0; i < n; i++) {
secretShares[i] = c.getSecretShareV2(polyNames[i], pubEthKeys, t, n); secretShares[i] = client->getSecretShare(polyNames[i], pubEthKeys, t, n);
for (uint8_t k = 0; k < t; k++) { for (uint8_t k = 0; k < t; k++) {
for (uint8_t j = 0; j < 4; j++) { for (uint8_t j = 0; j < 4; j++) {
string pubShare = verifVects[i]["verificationVector"][k][j].asString(); string pubShare = verifVects[i][k][j].asString();
pubShares[i] += convertDecToHex(pubShare); pubShares[i] += convertDecToHex(pubShare);
} }
} }
...@@ -441,10 +438,10 @@ void TestUtils::sendRPCRequestZMQ() { ...@@ -441,10 +438,10 @@ void TestUtils::sendRPCRequestZMQ() {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) { for (int j = 0; j < n; j++) {
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192); string secretShare = secretShares[i].substr(192 * j, 192);
secShares[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192); secShares[i] += secretShares[j].substr(192 * i, 192);
Json::Value verif = c.dkgVerificationV2(pubShares[i], ethKeys[j]["keyName"].asString(), secretShare, t, n, j); bool verif = client->dkgVerification(pubShares[i], ethKeys[j], secretShare, t, n, j);
CHECK_STATE(verif["status"] == 0); CHECK_STATE(verif);
} }
BLSSigShareSet sigShareSet(t, n); BLSSigShareSet sigShareSet(t, n);
...@@ -464,16 +461,30 @@ void TestUtils::sendRPCRequestZMQ() { ...@@ -464,16 +461,30 @@ void TestUtils::sendRPCRequestZMQ() {
publicShares["publicShares"][i] = pubShares[i]; publicShares["publicShares"][i] = pubShares[i];
} }
Json::Value blsPublicKeys = c.calculateAllBLSPublicKeys(publicShares, t, n); Json::Value blsPublicKeys = client->getAllBlsPublicKeys(publicShares, t, n);
CHECK_STATE(blsPublicKeys["status"] == 0);
for (int i = 0; i < t; i++) { for (int i = 0; i < t; i++) {
string blsName = "BLS_KEY" + polyNames[i].substr(4); string blsName = "BLS_KEY" + polyNames[i].substr(4);
string secretShare = secretShares[i];
CHECK_STATE(client->createBLSPrivateKey(blsName, ethKeys[i], polyNames[i], secShares[i], t, n));
pubBLSKeys[i] = client->getBLSPublicKey(blsName);
libff::alt_bn128_G2 publicKey(libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i][0].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i][1].asCString())),
libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i][2].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i][3].asCString())),
libff::alt_bn128_Fq2::one());
string public_key_str = convertG2ToString(publicKey);
CHECK_STATE(public_key_str == blsPublicKeys[i].asString());
string hash = SAMPLE_HASH; string hash = SAMPLE_HASH;
blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n); blsSigShares[i] = client->blsSignMessageHash(blsName, hash, t, n);
CHECK_STATE(blsSigShares[i]["status"] == 0); CHECK_STATE(blsSigShares[i].length() > 0);
shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString()); shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]);
BLSSigShare sig(sig_share_ptr, i + 1, t, n); BLSSigShare sig(sig_share_ptr, i + 1, t, n);
sigShareSet.addSigShare(make_shared<BLSSigShare>(sig)); sigShareSet.addSigShare(make_shared<BLSSigShare>(sig));
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#define SGXWALLET_TESTUTILS_H #define SGXWALLET_TESTUTILS_H
#include <dkg/dkg.h> #include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp> #include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <dkg/dkg.h> #include <dkg/dkg.h>
#include "sgxwallet_common.h" #include "sgxwallet_common.h"
......
1.76.0 1.77.0
\ No newline at end of file \ No newline at end of file
...@@ -981,6 +981,18 @@ TEST_CASE_METHOD(TestFixture, "Many threads ecdsa dkg v2 bls", "[many-threads-cr ...@@ -981,6 +981,18 @@ TEST_CASE_METHOD(TestFixture, "Many threads ecdsa dkg v2 bls", "[many-threads-cr
} }
} }
TEST_CASE_METHOD(TestFixture, "Many threads ecdsa dkg v2 bls zmq", "[many-threads-crypto-v2-zmq]") {
vector <thread> threads;
int num_threads = 4;
for (int i = 0; i < num_threads; i++) {
threads.push_back(thread(TestUtils::sendRPCRequestZMQ));
}
for (auto &thread : threads) {
thread.join();
}
}
TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") { TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") {
HttpClient client(RPC_ENDPOINT); HttpClient client(RPC_ENDPOINT);
......
...@@ -33,7 +33,7 @@ testList = [ "[zmq-ecdsa]", ...@@ -33,7 +33,7 @@ testList = [ "[zmq-ecdsa]",
"[second-run]", "[second-run]",
"[many-threads-crypto]", "[many-threads-crypto]",
"[many-threads-crypto-v2]", "[many-threads-crypto-v2]",
# "[many-threads-crypto-v2-zmq]" "[many-threads-crypto-v2-zmq]"
"[backup-restore]", "[backup-restore]",
"[cert-sign]", "[cert-sign]",
"[get-server-status]", "[get-server-status]",
......
...@@ -403,7 +403,7 @@ bool ZMQClient::dkgVerification(const string& publicShares, const string& ethKey ...@@ -403,7 +403,7 @@ bool ZMQClient::dkgVerification(const string& publicShares, const string& ethKey
return result->isCorrect(); return result->isCorrect();
} }
void ZMQClient::createBLSPrivateKey(const string& blsKeyName, const string& ethKeyName, const string& polyName, bool ZMQClient::createBLSPrivateKey(const string& blsKeyName, const string& ethKeyName, const string& polyName,
const string& secretShare, int t, int n) { const string& secretShare, int t, int n) {
Json::Value p; Json::Value p;
p["type"] = ZMQMessage::CREATE_BLS_PRIVATE_REQ; p["type"] = ZMQMessage::CREATE_BLS_PRIVATE_REQ;
...@@ -415,7 +415,7 @@ void ZMQClient::createBLSPrivateKey(const string& blsKeyName, const string& ethK ...@@ -415,7 +415,7 @@ void ZMQClient::createBLSPrivateKey(const string& blsKeyName, const string& ethK
p["n"] = n; p["n"] = n;
auto result = dynamic_pointer_cast<createBLSPrivateKeyRspMessage>(doRequestReply(p)); auto result = dynamic_pointer_cast<createBLSPrivateKeyRspMessage>(doRequestReply(p));
CHECK_STATE(result); CHECK_STATE(result);
CHECK_STATE(result->getStatus() == 0); return result->getStatus() == 0;
} }
Json::Value ZMQClient::getBLSPublicKey(const string& blsKeyName) { Json::Value ZMQClient::getBLSPublicKey(const string& blsKeyName) {
...@@ -431,7 +431,7 @@ Json::Value ZMQClient::getBLSPublicKey(const string& blsKeyName) { ...@@ -431,7 +431,7 @@ Json::Value ZMQClient::getBLSPublicKey(const string& blsKeyName) {
Json::Value ZMQClient::getAllBlsPublicKeys(const Json::Value& publicShares, int n, int t) { Json::Value ZMQClient::getAllBlsPublicKeys(const Json::Value& publicShares, int n, int t) {
Json::Value p; Json::Value p;
p["type"] = ZMQMessage::GET_ALL_BLS_PUBLIC_REQ; p["type"] = ZMQMessage::GET_ALL_BLS_PUBLIC_REQ;
p["publicShares"] = publicShares; p["publicShares"] = publicShares["publicShares"];
p["t"] = t; p["t"] = t;
p["n"] = n; p["n"] = n;
auto result = dynamic_pointer_cast<getAllBLSPublicKeysRspMessage>(doRequestReply(p)); auto result = dynamic_pointer_cast<getAllBLSPublicKeysRspMessage>(doRequestReply(p));
......
...@@ -104,7 +104,7 @@ public: ...@@ -104,7 +104,7 @@ public:
bool dkgVerification(const string& publicShares, const string& ethKeyName, bool dkgVerification(const string& publicShares, const string& ethKeyName,
const string& secretShare, int t, int n, int idx); const string& secretShare, int t, int n, int idx);
void createBLSPrivateKey(const string& blsKeyName, const string& ethKeyName, const string& polyName, bool createBLSPrivateKey(const string& blsKeyName, const string& ethKeyName, const string& polyName,
const string& secretShare, int t, int n); const string& secretShare, int t, int n);
Json::Value getBLSPublicKey(const string& blsKeyName); Json::Value getBLSPublicKey(const string& blsKeyName);
......
...@@ -46,7 +46,6 @@ Json::Value ZMQMessage::getJsonValueRapid(const char *_name) { ...@@ -46,7 +46,6 @@ Json::Value ZMQMessage::getJsonValueRapid(const char *_name) {
CHECK_STATE(_name); CHECK_STATE(_name);
CHECK_STATE(d->HasMember(_name)); CHECK_STATE(d->HasMember(_name));
const rapidjson::Value &a = (*d)[_name]; const rapidjson::Value &a = (*d)[_name];
CHECK_STATE(a.IsArray());
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer(buffer); rapidjson::Writer< rapidjson::StringBuffer > writer(buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment