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
2d186486
Unverified
Commit
2d186486
authored
Jan 18, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3751-enable-zeromq
parent
6545d811
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
59 deletions
+100
-59
ZMQClient.cpp
ZMQClient.cpp
+32
-6
ZMQClient.h
ZMQClient.h
+9
-3
ZMQServer.h
ZMQServer.h
+1
-1
testw.cpp
testw.cpp
+58
-49
No files found.
ZMQClient.cpp
View file @
2d186486
...
@@ -22,6 +22,9 @@
...
@@ -22,6 +22,9 @@
*/
*/
#include "sys/random.h"
#include "sys/random.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include "common.h"
#include "common.h"
#include "BLSSignReqMessage.h"
#include "BLSSignReqMessage.h"
...
@@ -62,14 +65,25 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
...
@@ -62,14 +65,25 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
throw
;
throw
;
}
}
}
}
string
ZMQClient
::
doZmqRequestReply
(
string
&
_req
)
{
string
ZMQClient
::
doZmqRequestReply
(
string
&
_req
)
{
stringstream
request
;
stringstream
request
;
if
(
!
clientSocket
)
shared_ptr
<
zmq
::
socket_t
>
clientSocket
=
nullptr
;
{
lock_guard
<
recursive_mutex
>
m
(
mutex
);
if
(
!
clientSockets
.
count
(
getProcessID
()))
reconnect
();
reconnect
();
clientSocket
=
clientSockets
.
at
(
getProcessID
());
CHECK_STATE
(
clientSocket
);
}
CHECK_STATE
(
clientSocket
);
CHECK_STATE
(
clientSocket
);
spdlog
::
debug
(
"ZMQ client sending:
\n
{}"
,
_req
);
spdlog
::
debug
(
"ZMQ client sending:
\n
{}"
,
_req
);
...
@@ -108,18 +122,24 @@ ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) {
...
@@ -108,18 +122,24 @@ ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) {
void
ZMQClient
::
reconnect
()
{
void
ZMQClient
::
reconnect
()
{
getrandom
(
identity
,
10
,
0
);
lock_guard
<
recursive_mutex
>
lock
(
mutex
);
auto
pid
=
getProcessID
();
if
(
clientSockets
.
count
(
pid
)
>
0
)
{
clientSockets
.
erase
(
pid
);
}
clientSocket
=
nullptr
;
// delete previous
char
identity
[
10
];
clientSocket
=
make_unique
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
getrandom
(
identity
,
10
,
0
);
auto
clientSocket
=
make_shared
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
clientSocket
->
setsockopt
(
ZMQ_IDENTITY
,
identity
,
10
);
clientSocket
->
setsockopt
(
ZMQ_IDENTITY
,
identity
,
10
);
// Configure socket to not wait at close time
// Configure socket to not wait at close time
int
linger
=
0
;
int
linger
=
0
;
clientSocket
->
setsockopt
(
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
clientSocket
->
setsockopt
(
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
clientSocket
->
connect
(
url
);
clientSocket
->
connect
(
url
);
clientSockets
.
insert
({
pid
,
clientSocket
});
}
}
...
@@ -148,3 +168,9 @@ string ZMQClient::ecdsaSignMessageHash(int base, const std::string &keyName, con
...
@@ -148,3 +168,9 @@ string ZMQClient::ecdsaSignMessageHash(int base, const std::string &keyName, con
CHECK_STATE
(
result
->
getStatus
()
==
0
);
CHECK_STATE
(
result
->
getStatus
()
==
0
);
return
result
->
getSignature
();
return
result
->
getSignature
();
}
}
uint64_t
ZMQClient
::
getProcessID
()
{
return
syscall
(
__NR_gettid
);
}
\ No newline at end of file
ZMQClient.h
View file @
2d186486
...
@@ -44,23 +44,29 @@ class ZMQClient {
...
@@ -44,23 +44,29 @@ class ZMQClient {
private
:
private
:
recursive_mutex
mutex
;
zmq
::
context_t
ctx
;
zmq
::
context_t
ctx
;
std
::
unique_ptr
<
zmq
::
socket_t
>
clientSocket
;
string
url
;
string
url
;
// generate random identity
// generate random identity
char
identity
[
10
]
=
{};
map
<
uint64_t
,
shared_ptr
<
zmq
::
socket_t
>>
clientSockets
;
shared_ptr
<
ZMQMessage
>
doRequestReply
(
Json
::
Value
&
_req
);
shared_ptr
<
ZMQMessage
>
doRequestReply
(
Json
::
Value
&
_req
);
string
doZmqRequestReply
(
string
&
_req
);
string
doZmqRequestReply
(
string
&
_req
);
uint64_t
getProcessID
();
public
:
public
:
ZMQClient
(
string
&
ip
,
uint16_t
port
);
ZMQClient
(
string
&
ip
,
uint16_t
port
);
void
reconnect
()
;
void
reconnect
()
;
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
...
...
ZMQServer.h
View file @
2d186486
...
@@ -47,7 +47,7 @@ public:
...
@@ -47,7 +47,7 @@ public:
ZMQServer
();
ZMQServer
();
enum
{
enum
{
kMaxThread
=
1
6
kMaxThread
=
1
};
};
void
run
();
void
run
();
...
...
testw.cpp
View file @
2d186486
...
@@ -381,7 +381,7 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares test", "[dkg-aes-
...
@@ -381,7 +381,7 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares test", "[dkg-aes-
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
PRINT_SRC_LINE
PRINT_SRC_LINE
status
=
trustedGetEncryptedSecretShare
(
eid
,
&
errStatus
,
errMsg
.
data
(),
status
=
trustedGetEncryptedSecretShare
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
(),
encLen
,
encryptedDKGSecret
.
data
(),
encLen
,
encrPRDHKey
.
data
(),
&
encLen
,
encrPRDHKey
.
data
(),
&
encLen
,
result
.
data
(),
result
.
data
(),
...
@@ -411,7 +411,7 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares version 2 test",
...
@@ -411,7 +411,7 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares version 2 test",
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
PRINT_SRC_LINE
PRINT_SRC_LINE
status
=
trustedGetEncryptedSecretShareV2
(
eid
,
&
errStatus
,
errMsg
.
data
(),
status
=
trustedGetEncryptedSecretShareV2
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
(),
encLen
,
encryptedDKGSecret
.
data
(),
encLen
,
encrPRDHKey
.
data
(),
&
encLen
,
encrPRDHKey
.
data
(),
&
encLen
,
result
.
data
(),
result
.
data
(),
...
@@ -510,7 +510,8 @@ TEST_CASE_METHOD(TestFixture, "Import ECDSA Key", "[import-ecdsa-key]") {
...
@@ -510,7 +510,8 @@ TEST_CASE_METHOD(TestFixture, "Import ECDSA Key", "[import-ecdsa-key]") {
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
std
::
string
name
=
"NEK:abcdef"
;
std
::
string
name
=
"NEK:abcdef"
;
auto
response
=
c
.
importECDSAKey
(
"6507625568967977077291849236396320012317305261598035438182864059942098934847"
,
name
);
auto
response
=
c
.
importECDSAKey
(
"6507625568967977077291849236396320012317305261598035438182864059942098934847"
,
name
);
REQUIRE
(
response
[
"status"
]
!=
0
);
REQUIRE
(
response
[
"status"
]
!=
0
);
string
key_str
=
"0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"
;
string
key_str
=
"0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"
;
...
@@ -781,7 +782,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
...
@@ -781,7 +782,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
vector
<
char
>
message
(
65
,
0
);
vector
<
char
>
message
(
65
,
0
);
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
...
@@ -804,7 +805,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
...
@@ -804,7 +805,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
mpz_clear
(
hex_share
);
mpz_clear
(
hex_share
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
Json
::
Value
verificationVectorMult
=
complaintResponse
[
"verificationVectorMult"
];
Json
::
Value
verificationVectorMult
=
complaintResponse
[
"verificationVectorMult"
];
...
@@ -819,13 +820,14 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
...
@@ -819,13 +820,14 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
verificationValue
=
verificationValue
+
value
;
verificationValue
=
verificationValue
+
value
;
}
}
verificationValue
.
to_affine_coordinates
();
verificationValue
.
to_affine_coordinates
();
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
uint64_t
binLen
;
uint64_t
binLen
;
...
@@ -926,7 +928,8 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -926,7 +928,8 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
secShares
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
PRINT_SRC_LINE
PRINT_SRC_LINE
Json
::
Value
verif
=
c
.
dkgVerificationV2
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
Json
::
Value
verif
=
c
.
dkgVerificationV2
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
REQUIRE
(
verif
[
"status"
]
==
0
);
REQUIRE
(
verif
[
"status"
]
==
0
);
bool
res
=
verif
[
"result"
].
asBool
();
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
k
++
;
...
@@ -940,7 +943,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -940,7 +943,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
vector
<
char
>
message
(
65
,
0
);
vector
<
char
>
message
(
65
,
0
);
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
...
@@ -953,7 +956,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -953,7 +956,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
SAFE_CHAR_BUF
(
derived_key
,
33
)
SAFE_CHAR_BUF
(
derived_key
,
33
)
uint64_t
key_length
;
uint64_t
key_length
;
REQUIRE
(
hex2carray
(
&
hashed_key
[
0
],
&
key_length
,
(
uint8_t
*
)
derived_key
,
33
));
REQUIRE
(
hex2carray
(
&
hashed_key
[
0
],
&
key_length
,
(
uint8_t
*
)
derived_key
,
33
));
SAFE_CHAR_BUF
(
encr_sshare_check
,
BUF_LEN
)
SAFE_CHAR_BUF
(
encr_sshare_check
,
BUF_LEN
)
strncpy
(
encr_sshare_check
,
secretShare
.
c_str
(),
ECDSA_SKEY_LEN
-
1
);
strncpy
(
encr_sshare_check
,
secretShare
.
c_str
(),
ECDSA_SKEY_LEN
-
1
);
...
@@ -970,7 +973,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -970,7 +973,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
mpz_clear
(
hex_share
);
mpz_clear
(
hex_share
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
Json
::
Value
verificationVectorMult
=
complaintResponse
[
"verificationVectorMult"
];
Json
::
Value
verificationVectorMult
=
complaintResponse
[
"verificationVectorMult"
];
...
@@ -985,13 +988,14 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -985,13 +988,14 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
verificationValue
=
verificationValue
+
value
;
verificationValue
=
verificationValue
+
value
;
}
}
verificationValue
.
to_affine_coordinates
();
verificationValue
.
to_affine_coordinates
();
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
uint64_t
binLen
;
uint64_t
binLen
;
...
@@ -1004,7 +1008,8 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -1004,7 +1008,8 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
auto
response
=
c
.
createBLSPrivateKeyV2
(
blsName
,
ethKeys
[
i
][
"keyName"
].
asString
(),
polyNames
[
i
],
secShares
[
i
],
t
,
auto
response
=
c
.
createBLSPrivateKeyV2
(
blsName
,
ethKeys
[
i
][
"keyName"
].
asString
(),
polyNames
[
i
],
secShares
[
i
],
t
,
n
);
n
);
REQUIRE
(
response
[
"status"
]
==
0
);
REQUIRE
(
response
[
"status"
]
==
0
);
...
@@ -1095,8 +1100,7 @@ TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") {
...
@@ -1095,8 +1100,7 @@ TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") {
namefile
<<
keyName
;
namefile
<<
keyName
;
PRINT_SRC_LINE
PRINT_SRC_LINE
}
catch
(
JsonRpcException
&
e
)
}
catch
(
JsonRpcException
&
e
)
{
{
cerr
<<
e
.
what
()
<<
endl
;
cerr
<<
e
.
what
()
<<
endl
;
throw
;
throw
;
}
}
...
@@ -1125,7 +1129,6 @@ TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") {
...
@@ -1125,7 +1129,6 @@ TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") {
}
}
TEST_CASE_METHOD
(
TestFixture
,
"ZMQ-ecdsa"
,
"[zmq-ecdsa]"
)
{
TEST_CASE_METHOD
(
TestFixture
,
"ZMQ-ecdsa"
,
"[zmq-ecdsa]"
)
{
HttpClient
htp
(
RPC_ENDPOINT
);
HttpClient
htp
(
RPC_ENDPOINT
);
...
@@ -1139,25 +1142,31 @@ TEST_CASE_METHOD(TestFixture, "ZMQ-ecdsa", "[zmq-ecdsa]") {
...
@@ -1139,25 +1142,31 @@ TEST_CASE_METHOD(TestFixture, "ZMQ-ecdsa", "[zmq-ecdsa]") {
PRINT_SRC_LINE
PRINT_SRC_LINE
keyName
=
genECDSAKeyAPI
(
c
);
keyName
=
genECDSAKeyAPI
(
c
);
int
end
=
10000000
;
int
end
=
100000
;
string
sh
=
string
(
SAMPLE_HASH
);
string
sh
=
string
(
SAMPLE_HASH
);
std
::
vector
<
std
::
thread
>
workers
;
PRINT_SRC_LINE
PRINT_SRC_LINE
for
(
int
i
=
1
;
i
<
10000
;
i
++
)
{
auto
hash
=
sh
.
substr
(
0
,
sh
.
size
()
-
6
)
+
to_string
(
end
+
i
);
for
(
int
j
=
0
;
j
<
10
;
j
++
)
{
workers
.
push_back
(
std
::
thread
([
client
,
sh
,
keyName
,
end
,
j
]()
{
CHECK_STATE
(
client
);
for
(
int
i
=
(
j
*
2000
);
i
<
(
j
*
2000
)
+
1000
;
i
++
)
{
auto
hash
=
sh
.
substr
(
0
,
sh
.
size
()
-
8
)
+
to_string
(
end
+
i
);
auto
sig
=
client
->
ecdsaSignMessageHash
(
16
,
keyName
,
hash
);
auto
sig
=
client
->
ecdsaSignMessageHash
(
16
,
keyName
,
hash
);
REQUIRE
(
sig
.
size
()
>
10
);
REQUIRE
(
sig
.
size
()
>
10
);
}
}
}));
};
std
::
for_each
(
workers
.
begin
(),
workers
.
end
(),
[](
std
::
thread
&
t
)
{
t
.
join
();
});
PRINT_SRC_LINE
PRINT_SRC_LINE
}
}
...
...
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