Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
ab08ff9d
Unverified
Commit
ab08ff9d
authored
Jun 08, 2021
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3951 add tests, update VERSION
parent
f423edba
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
35 deletions
+56
-35
TestUtils.cpp
TestUtils.cpp
+38
-27
TestUtils.h
TestUtils.h
+0
-1
VERSION
VERSION
+1
-1
testw.cpp
testw.cpp
+12
-0
testw.py
testw.py
+1
-1
ZMQClient.cpp
zmq_src/ZMQClient.cpp
+3
-3
ZMQClient.h
zmq_src/ZMQClient.h
+1
-1
ZMQMessage.cpp
zmq_src/ZMQMessage.cpp
+0
-1
No files found.
TestUtils.cpp
View file @
ab08ff9d
...
...
@@ -42,7 +42,6 @@
#include "SGXWalletServer.hpp"
#include "catch.hpp"
#include "zmq_src/ZMQClient.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
...
...
@@ -396,42 +395,40 @@ void TestUtils::sendRPCRequestV2() {
}
void
TestUtils
::
sendRPCRequestZMQ
()
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
auto
client
=
make_shared
<
ZMQClient
>
(
ZMQ_IP
,
ZMQ_PORT
,
true
,
"./sgx_data/cert_data/rootCA.pem"
,
"./sgx_data/cert_data/rootCA.key"
);
int
n
=
16
,
t
=
16
;
Json
::
Value
ethKeys
[
n
]
;
vector
<
string
>
ethKeys
(
n
)
;
Json
::
Value
verifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
]
;
vector
<
string
>
secretShares
(
n
)
;
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
blsSigShares
[
n
]
;
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
polyNames
(
n
);
vector
<
string
>
blsSigShares
(
n
)
;
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
polyNames
(
n
);
static
atomic
<
int
>
counter
(
1
);
int
schainID
=
counter
.
fetch_add
(
1
);
int
dkgID
=
counter
.
fetch_add
(
1
);
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
ethKeys
[
i
]
=
c
.
generateECDSAKey
();
CHECK_STATE
(
ethKeys
[
i
][
"status"
]
==
0
)
;
auto
generatedKey
=
client
->
generateECDSAKey
();
ethKeys
[
i
]
=
generatedKey
.
second
;
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schainID
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkgID
);
auto
response
=
c
.
generateDKGPoly
(
polyName
,
t
);
CHECK_STATE
(
response
[
"status"
]
==
0
);
CHECK_STATE
(
client
->
generateDKGPoly
(
polyName
,
t
));
polyNames
[
i
]
=
polyName
;
verifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
);
CHECK_STATE
(
verifVects
[
i
][
"status"
]
==
0
);
verifVects
[
i
]
=
client
->
getVerificationVector
(
polyName
,
t
);
pubEthKeys
.
append
(
ethKeys
[
i
][
"publicKey"
]
);
pubEthKeys
.
append
(
generatedKey
.
first
);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShareV2
(
polyNames
[
i
],
pubEthKeys
,
t
,
n
);
secretShares
[
i
]
=
c
lient
->
getSecretShare
(
polyNames
[
i
],
pubEthKeys
,
t
,
n
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
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
);
}
}
...
...
@@ -441,10 +438,10 @@ void TestUtils::sendRPCRequestZMQ() {
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
string
secretShare
=
secretShares
[
i
]
[
"secretShare"
].
asString
()
.
substr
(
192
*
j
,
192
);
secShares
[
i
]
+=
secretShares
[
j
]
[
"secretShare"
].
asString
()
.
substr
(
192
*
i
,
192
);
Json
::
Value
verif
=
c
.
dkgVerificationV2
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
()
,
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
verif
[
"status"
]
==
0
);
string
secretShare
=
secretShares
[
i
].
substr
(
192
*
j
,
192
);
secShares
[
i
]
+=
secretShares
[
j
].
substr
(
192
*
i
,
192
);
bool
verif
=
client
->
dkgVerification
(
pubShares
[
i
],
ethKeys
[
j
]
,
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
verif
);
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
...
@@ -464,16 +461,30 @@ void TestUtils::sendRPCRequestZMQ() {
publicShares
[
"publicShares"
][
i
]
=
pubShares
[
i
];
}
Json
::
Value
blsPublicKeys
=
c
.
calculateAllBLSPublicKeys
(
publicShares
,
t
,
n
);
CHECK_STATE
(
blsPublicKeys
[
"status"
]
==
0
);
Json
::
Value
blsPublicKeys
=
client
->
getAllBlsPublicKeys
(
publicShares
,
t
,
n
);
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
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
;
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
]
[
"status"
]
==
0
);
blsSigShares
[
i
]
=
c
lient
->
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
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
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
}
...
...
TestUtils.h
View file @
ab08ff9d
...
...
@@ -25,7 +25,6 @@
#define SGXWALLET_TESTUTILS_H
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
...
...
VERSION
View file @
ab08ff9d
1.76.0
\ No newline at end of file
1.77.0
\ No newline at end of file
testw.cpp
View file @
ab08ff9d
...
...
@@ -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]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
...
...
testw.py
View file @
ab08ff9d
...
...
@@ -33,7 +33,7 @@ testList = [ "[zmq-ecdsa]",
"[second-run]"
,
"[many-threads-crypto]"
,
"[many-threads-crypto-v2]"
,
#
"[many-threads-crypto-v2-zmq]"
"[many-threads-crypto-v2-zmq]"
"[backup-restore]"
,
"[cert-sign]"
,
"[get-server-status]"
,
...
...
zmq_src/ZMQClient.cpp
View file @
ab08ff9d
...
...
@@ -403,7 +403,7 @@ bool ZMQClient::dkgVerification(const string& publicShares, const string& ethKey
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
)
{
Json
::
Value
p
;
p
[
"type"
]
=
ZMQMessage
::
CREATE_BLS_PRIVATE_REQ
;
...
...
@@ -415,7 +415,7 @@ void ZMQClient::createBLSPrivateKey(const string& blsKeyName, const string& ethK
p
[
"n"
]
=
n
;
auto
result
=
dynamic_pointer_cast
<
createBLSPrivateKeyRspMessage
>
(
doRequestReply
(
p
));
CHECK_STATE
(
result
);
CHECK_STATE
(
result
->
getStatus
()
==
0
)
;
return
result
->
getStatus
()
==
0
;
}
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
p
;
p
[
"type"
]
=
ZMQMessage
::
GET_ALL_BLS_PUBLIC_REQ
;
p
[
"publicShares"
]
=
publicShares
;
p
[
"publicShares"
]
=
publicShares
[
"publicShares"
]
;
p
[
"t"
]
=
t
;
p
[
"n"
]
=
n
;
auto
result
=
dynamic_pointer_cast
<
getAllBLSPublicKeysRspMessage
>
(
doRequestReply
(
p
));
...
...
zmq_src/ZMQClient.h
View file @
ab08ff9d
...
...
@@ -104,7 +104,7 @@ public:
bool
dkgVerification
(
const
string
&
publicShares
,
const
string
&
ethKeyName
,
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
);
Json
::
Value
getBLSPublicKey
(
const
string
&
blsKeyName
);
...
...
zmq_src/ZMQMessage.cpp
View file @
ab08ff9d
...
...
@@ -46,7 +46,6 @@ Json::Value ZMQMessage::getJsonValueRapid(const char *_name) {
CHECK_STATE
(
_name
);
CHECK_STATE
(
d
->
HasMember
(
_name
));
const
rapidjson
::
Value
&
a
=
(
*
d
)[
_name
];
CHECK_STATE
(
a
.
IsArray
());
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment