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
462d89ea
Unverified
Commit
462d89ea
authored
Nov 17, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3504 add tests
parent
66bfa4de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
583 additions
and
1 deletion
+583
-1
TestUtils.cpp
TestUtils.cpp
+245
-0
TestUtils.h
TestUtils.h
+6
-0
abstractstubserver.h
abstractstubserver.h
+15
-0
stubclient.h
stubclient.h
+30
-0
testw.cpp
testw.cpp
+281
-0
testw.py
testw.py
+6
-1
No files found.
TestUtils.cpp
View file @
462d89ea
...
...
@@ -262,6 +262,110 @@ void TestUtils::sendRPCRequest() {
sigShareSet
.
merge
();
}
void
TestUtils
::
sendRPCRequestV2
()
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
int
n
=
16
,
t
=
16
;
Json
::
Value
ethKeys
[
n
];
Json
::
Value
verifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
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
);
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
);
polyNames
[
i
]
=
polyName
;
verifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
CHECK_STATE
(
verifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
ethKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShareV2
(
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
();
pubShares
[
i
]
+=
convertDecToHex
(
pubShare
);
}
}
}
vector
<
string
>
secShares
(
n
);
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
);
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
(),
32
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coeffs_pkeys_map
;
Json
::
Value
publicShares
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
publicShares
[
"publicShares"
][
i
]
=
pubShares
[
i
];
}
Json
::
Value
blsPublicKeys
=
c
.
calculateAllBLSPublicKeys
(
publicShares
,
t
,
n
);
CHECK_STATE
(
blsPublicKeys
[
"status"
]
==
0
);
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
auto
response
=
c
.
createBLSPrivateKey
(
blsName
,
ethKeys
[
i
][
"keyName"
].
asString
(),
polyNames
[
i
],
secShares
[
i
],
t
,
n
);
CHECK_STATE
(
response
[
"status"
]
==
0
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
CHECK_STATE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
libff
::
alt_bn128_G2
publicKey
(
libff
::
alt_bn128_Fq2
(
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
0
].
asCString
()),
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
1
].
asCString
())),
libff
::
alt_bn128_Fq2
(
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
2
].
asCString
()),
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
3
].
asCString
())),
libff
::
alt_bn128_Fq2
::
one
());
string
public_key_str
=
convertG2ToString
(
publicKey
);
CHECK_STATE
(
public_key_str
==
blsPublicKeys
[
"publicKeys"
][
i
].
asString
());
string
hash
=
SAMPLE_HASH
;
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
}
sigShareSet
.
merge
();
}
void
TestUtils
::
destroyEnclave
()
{
if
(
eid
!=
0
)
{
sgx_destroy_enclave
(
eid
);
...
...
@@ -410,6 +514,147 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
cerr
<<
i
<<
endl
;
}
void
TestUtils
::
doDKGV2
(
StubClient
&
c
,
int
n
,
int
t
,
vector
<
string
>&
_ecdsaKeyNames
,
vector
<
string
>&
_blsKeyNames
,
int
schainID
,
int
dkgID
)
{
Json
::
Value
ethKeys
[
n
];
Json
::
Value
verifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
blsSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
polyNames
(
n
);
_ecdsaKeyNames
.
clear
();
_blsKeyNames
.
clear
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
ethKeys
[
i
]
=
c
.
generateECDSAKey
();
CHECK_STATE
(
ethKeys
[
i
][
"status"
]
==
0
);
auto
keyName
=
ethKeys
[
i
][
"keyName"
].
asString
();
CHECK_STATE
(
keyName
.
size
()
==
ECDSA_KEY_NAME_SIZE
);
_ecdsaKeyNames
.
push_back
(
keyName
);
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schainID
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkgID
);
Json
::
Value
response
=
c
.
generateDKGPoly
(
polyName
,
t
);
CHECK_STATE
(
response
[
"status"
]
==
0
);
polyNames
[
i
]
=
polyName
;
verifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
CHECK_STATE
(
verifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
ethKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShareV2
(
polyNames
[
i
],
pubEthKeys
,
t
,
n
);
CHECK_STATE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
verifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
CHECK_STATE
(
pubShare
.
length
()
>
60
);
pubShares
[
i
]
+=
TestUtils
::
convertDecToHex
(
pubShare
);
}
}
}
int
k
=
0
;
vector
<
string
>
secShares
(
n
);
vector
<
string
>
pSharesBad
(
pubShares
);
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
response
=
c
.
dkgVerificationV2
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
response
[
"status"
]
==
0
);
bool
res
=
response
[
"result"
].
asBool
();
CHECK_STATE
(
res
);
k
++
;
pSharesBad
[
i
][
0
]
=
'q'
;
Json
::
Value
wrongVerif
=
c
.
dkgVerificationV2
(
pSharesBad
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
res
=
wrongVerif
[
"result"
].
asBool
();
CHECK_STATE
(
!
res
);
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
(),
32
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
pubKeyShares
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
_blsKeyNames
.
push_back
(
blsName
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
auto
response
=
c
.
createBLSPrivateKey
(
blsName
,
ethKeys
[
i
][
"keyName"
].
asString
(),
polyNames
[
i
],
secShares
[
i
],
t
,
n
);
CHECK_STATE
(
response
[
"status"
]
==
0
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
CHECK_STATE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
}
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
vector
<
string
>
pubKeyVect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
pubKeyVect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKeyVect
),
t
,
n
);
pubKeyShares
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
// create pub key
BLSPublicKey
blsPublicKey
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
pubKeyShares
),
t
,
n
);
// sign verify a sample sig
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
auto
pubKey
=
pubKeyShares
[
i
+
1
];
CHECK_STATE
(
pubKey
->
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
CHECK_STATE
(
blsPublicKey
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
for
(
auto
&&
i
:
_ecdsaKeyNames
)
cerr
<<
i
<<
endl
;
for
(
auto
&&
i
:
_blsKeyNames
)
cerr
<<
i
<<
endl
;
}
int
sessionKeyRecoverDH
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
int
ret
=
-
1
;
...
...
TestUtils.h
View file @
462d89ea
...
...
@@ -70,11 +70,17 @@ public:
static
void
sendRPCRequest
();
static
void
sendRPCRequestV2
();
static
void
destroyEnclave
();
static
void
doDKG
(
StubClient
&
c
,
int
n
,
int
t
,
vector
<
string
>&
_ecdsaKeyNames
,
vector
<
string
>&
_blsKeyNames
,
int
schainID
,
int
dkgID
);
static
void
doDKGV2
(
StubClient
&
c
,
int
n
,
int
t
,
vector
<
string
>&
_ecdsaKeyNames
,
vector
<
string
>&
_blsKeyNames
,
int
schainID
,
int
dkgID
);
};
int
sessionKeyRecoverDH
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
);
...
...
abstractstubserver.h
View file @
462d89ea
...
...
@@ -58,6 +58,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getServerStatus"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractStubServer
::
getServerStatusI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getServerVersion"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractStubServer
::
getServerVersionI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"deleteBlsKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
deleteBlsKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getSecretShareV2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"publicKeys"
,
jsonrpc
::
JSON_ARRAY
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
getSecretShareV2I
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"dkgVerificationV2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"publicShares"
,
jsonrpc
::
JSON_STRING
,
"ethKeyName"
,
jsonrpc
::
JSON_STRING
,
"secretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"index"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
dkgVerificationV2I
);
}
inline
virtual
void
importBLSKeyShareI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
...
...
@@ -144,6 +147,15 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response
=
this
->
deleteBlsKey
(
request
[
"blsKeyName"
].
asString
());
}
inline
virtual
void
getSecretShareV2I
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
getSecretShareV2
(
request
[
"polyName"
].
asString
(),
request
[
"publicKeys"
],
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
());
}
inline
virtual
void
dkgVerificationV2I
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
dkgVerificationV2
(
request
[
"publicShares"
].
asString
(),
request
[
"ethKeyName"
].
asString
(),
request
[
"secretShare"
].
asString
(),
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
(),
request
[
"index"
].
asInt
());
}
virtual
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
)
=
0
;
...
...
@@ -165,6 +177,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
getServerStatus
()
=
0
;
virtual
Json
::
Value
getServerVersion
()
=
0
;
virtual
Json
::
Value
deleteBlsKey
(
const
std
::
string
&
name
)
=
0
;
virtual
Json
::
Value
getSecretShareV2
(
const
std
::
string
&
polyName
,
const
Json
::
Value
&
publicKeys
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
dkgVerificationV2
(
const
std
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
=
0
;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
stubclient.h
View file @
462d89ea
...
...
@@ -125,6 +125,20 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
getSecretShareV2
(
const
std
::
string
&
polyName
,
const
Json
::
Value
&
publicKeys
,
int
t
,
int
n
)
{
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"publicKeys"
]
=
publicKeys
;
p
[
"n"
]
=
n
;
p
[
"t"
]
=
t
;
Json
::
Value
result
=
this
->
CallMethod
(
"getSecretShareV2"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
dkgVerification
(
const
std
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
{
Json
::
Value
p
;
...
...
@@ -141,6 +155,22 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
dkgVerificationV2
(
const
std
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
{
Json
::
Value
p
;
p
[
"ethKeyName"
]
=
ethKeyName
;
p
[
"secretShare"
]
=
SecretShare
;
p
[
"index"
]
=
index
;
p
[
"n"
]
=
n
;
p
[
"publicShares"
]
=
publicShares
;
p
[
"t"
]
=
t
;
Json
::
Value
result
=
this
->
CallMethod
(
"dkgVerificationV2"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
createBLSPrivateKey
(
const
std
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
)
{
Json
::
Value
p
;
...
...
testw.cpp
View file @
462d89ea
...
...
@@ -387,6 +387,36 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares test", "[dkg-aes-
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
}
TEST_CASE_METHOD
(
TestFixture
,
"DKG AES encrypted secret shares version 2 test"
,
"[dkg-aes-encr-sshares-v2]"
)
{
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
result
(
BUF_LEN
,
0
);
int
errStatus
=
0
;
uint64_t
encLen
=
0
;
vector
<
uint8_t
>
encryptedDKGSecret
(
BUF_LEN
,
0
);
PRINT_SRC_LINE
auto
status
=
trustedGenDkgSecret
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
(),
&
encLen
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
vector
<
uint8_t
>
encrPRDHKey
(
BUF_LEN
,
0
);
string
pub_keyB
=
SAMPLE_PUBLIC_KEY_B
;
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
PRINT_SRC_LINE
status
=
trustedGetEncryptedSecretShareV2
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
(),
encLen
,
encrPRDHKey
.
data
(),
&
encLen
,
result
.
data
(),
s_shareG2
.
data
(),
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
}
/*
* ( "verification test", "[verify]" ) {
...
...
@@ -429,6 +459,27 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
TestUtils
::
doDKG
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
}
TEST_CASE_METHOD
(
TestFixture
,
"DKG_BLS V2 test"
,
"[dkg-bls-v2]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
vector
<
string
>
ecdsaKeyNames
;
vector
<
string
>
blsKeyNames
;
int
schainID
=
TestUtils
::
randGen
();
int
dkgID
=
TestUtils
::
randGen
();
PRINT_SRC_LINE
TestUtils
::
doDKGV2
(
c
,
4
,
1
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
REQUIRE
(
blsKeyNames
.
size
()
==
4
);
schainID
=
TestUtils
::
randGen
();
dkgID
=
TestUtils
::
randGen
();
TestUtils
::
doDKGV2
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
}
TEST_CASE_METHOD
(
TestFixture
,
"Delete Bls Key"
,
"[delete-bls-key]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
...
@@ -578,6 +629,66 @@ TEST_CASE_METHOD(TestFixture, "DKG API test", "[dkg-api]") {
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
}
TEST_CASE_METHOD
(
TestFixture
,
"DKG API V2 test"
,
"[dkg-api-v2]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
string
polyName
=
SAMPLE_POLY_NAME
;
PRINT_SRC_LINE
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
REQUIRE
(
genPoly
[
"status"
].
asInt
()
==
0
);
Json
::
Value
publicKeys
;
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_1
);
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_2
);
// wrongName
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
REQUIRE
(
genPolyWrongName
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
verifVectWrongName
=
c
.
getVerificationVector
(
"poly"
,
2
,
2
);
REQUIRE
(
verifVectWrongName
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
secretSharesWrongName
=
c
.
getSecretShareV2
(
"poly"
,
publicKeys
,
2
,
2
);
REQUIRE
(
secretSharesWrongName
[
"status"
].
asInt
()
!=
0
);
// wrong_t
Json
::
Value
genPolyWrong_t
=
c
.
generateDKGPoly
(
polyName
,
33
);
REQUIRE
(
genPolyWrong_t
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
verifVectWrong_t
=
c
.
getVerificationVector
(
polyName
,
1
,
2
);
REQUIRE
(
verifVectWrong_t
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
secretSharesWrong_t
=
c
.
getSecretShareV2
(
polyName
,
publicKeys
,
3
,
3
);
REQUIRE
(
secretSharesWrong_t
[
"status"
].
asInt
()
!=
0
);
// wrong_n
Json
::
Value
verifVectWrong_n
=
c
.
getVerificationVector
(
polyName
,
2
,
1
);
REQUIRE
(
verifVectWrong_n
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
publicKeys1
;
publicKeys1
.
append
(
SAMPLE_DKG_PUB_KEY_1
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShareV2
(
polyName
,
publicKeys1
,
2
,
1
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
//wrong number of publicKeys
Json
::
Value
secretSharesWrongPkeys
=
c
.
getSecretShareV2
(
polyName
,
publicKeys
,
2
,
3
);
REQUIRE
(
secretSharesWrongPkeys
[
"status"
].
asInt
()
!=
0
);
//wrong verif
Json
::
Value
Skeys
=
c
.
getSecretShareV2
(
polyName
,
publicKeys
,
2
,
2
);
REQUIRE_NOTHROW
(
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
));
REQUIRE
(
Skeys
==
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
));
Json
::
Value
verifVect
=
c
.
getVerificationVector
(
polyName
,
2
,
2
);
REQUIRE_NOTHROW
(
c
.
getVerificationVector
(
polyName
,
2
,
2
));
REQUIRE
(
verifVect
==
c
.
getVerificationVector
(
polyName
,
2
,
2
));
Json
::
Value
verificationWrongSkeys
=
c
.
dkgVerificationV2
(
""
,
""
,
""
,
2
,
2
,
1
);
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
}
TEST_CASE_METHOD
(
TestFixture
,
"PolyExists test"
,
"[dkg-poly-exists]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
...
@@ -756,6 +867,164 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
TEST_CASE_METHOD
(
TestFixture
,
"AES_DKG V2 test"
,
"[aes-dkg-v2]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
int
n
=
2
,
t
=
2
;
Json
::
Value
ethKeys
[
n
];
Json
::
Value
verifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
blsSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
polyNames
(
n
);
int
schainID
=
TestUtils
::
randGen
();
int
dkgID
=
TestUtils
::
randGen
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
PRINT_SRC_LINE
ethKeys
[
i
]
=
c
.
generateECDSAKey
();
REQUIRE
(
ethKeys
[
i
][
"status"
]
==
0
);
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schainID
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkgID
);
REQUIRE
(
ethKeys
[
i
][
"status"
]
==
0
);
auto
response
=
c
.
generateDKGPoly
(
polyName
,
t
);
REQUIRE
(
response
[
"status"
]
==
0
);
polyNames
[
i
]
=
polyName
;
PRINT_SRC_LINE
verifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
REQUIRE
(
verifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
ethKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
PRINT_SRC_LINE
secretShares
[
i
]
=
c
.
getSecretShareV2
(
polyNames
[
i
],
pubEthKeys
,
t
,
n
);
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
verifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
TestUtils
::
convertDecToHex
(
pubShare
);
}
}
int
k
=
0
;
vector
<
string
>
secShares
(
n
);
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
);
PRINT_SRC_LINE
Json
::
Value
verif
=
c
.
dkgVerificationV2
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
REQUIRE
(
verif
[
"status"
]
==
0
);
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
REQUIRE
(
res
);
}
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
string
dhKey
=
complaintResponse
[
"dhKey"
].
asString
();
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
vector
<
char
>
message
(
65
,
0
);
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
SAFE_CHAR_BUF
(
common_key
,
BUF_LEN
);
REQUIRE
(
sessionKeyRecoverDH
(
dhKey
.
c_str
(),
encr_sshare
,
common_key
)
==
0
);
SAFE_CHAR_BUF
(
encr_sshare_check
,
BUF_LEN
)
strncpy
(
encr_sshare_check
,
secretShare
.
c_str
(),
ECDSA_SKEY_LEN
-
1
);
REQUIRE
(
xorDecryptDH
(
common_key
,
encr_sshare_check
,
message
)
==
0
);
mpz_t
hex_share
;
mpz_init
(
hex_share
);
mpz_set_str
(
hex_share
,
message
.
data
(),
16
);
libff
::
alt_bn128_Fr
share
(
hex_share
);
libff
::
alt_bn128_G2
decrypted_share_G2
=
share
*
libff
::
alt_bn128_G2
::
one
();
decrypted_share_G2
.
to_affine_coordinates
();
mpz_clear
(
hex_share
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
Json
::
Value
verificationVectorMult
=
complaintResponse
[
"verificationVectorMult"
];
libff
::
alt_bn128_G2
verificationValue
=
libff
::
alt_bn128_G2
::
zero
();
for
(
int
i
=
0
;
i
<
t
;
++
i
)
{
libff
::
alt_bn128_G2
value
;
value
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
value
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
0
].
asCString
());
value
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
1
].
asCString
());
value
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
2
].
asCString
());
value
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
3
].
asCString
());
verificationValue
=
verificationValue
+
value
;
}
verificationValue
.
to_affine_coordinates
();
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
(),
32
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coeffs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
auto
response
=
c
.
createBLSPrivateKey
(
blsName
,
ethKeys
[
i
][
"keyName"
].
asString
(),
polyNames
[
i
],
secShares
[
i
],
t
,
n
);
REQUIRE
(
response
[
"status"
]
==
0
);
PRINT_SRC_LINE
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
string
hash
=
SAMPLE_HASH
;
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
REQUIRE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
PRINT_SRC_LINE
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
coeffs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
coeffs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
TEST_CASE_METHOD
(
TestFixture
,
"AES encrypt/decrypt"
,
"[aes-encrypt-decrypt]"
)
{
int
errStatus
=
0
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
...
...
@@ -791,6 +1060,18 @@ TEST_CASE_METHOD(TestFixture, "Many threads ecdsa dkg bls", "[many-threads-crypt
}
}
TEST_CASE_METHOD
(
TestFixture
,
"Many threads ecdsa dkg v2 bls"
,
"[many-threads-crypto-v2]"
)
{
vector
<
thread
>
threads
;
int
num_threads
=
4
;
for
(
int
i
=
0
;
i
<
num_threads
;
i
++
)
{
threads
.
push_back
(
thread
(
TestUtils
::
sendRPCRequest
));
}
for
(
auto
&
thread
:
threads
)
{
thread
.
join
();
}
}
TEST_CASE_METHOD
(
TestFixture
,
"First run"
,
"[first-run]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
...
...
testw.py
View file @
462d89ea
...
...
@@ -44,13 +44,18 @@ testList = ["[first-run]",
"[bls-key-encrypt]"
,
"[dkg-aes-gen]"
,
"[dkg-aes-encr-sshares]"
,
"[dkg-aes-encr-sshares-v2]"
,
"[dkg-api]"
,
"[dkg-api-v2]"
,
"[dkg-bls]"
,
"[dkg-bls-v2]"
,
"[dkg-poly-exists]"
,
"[dkg-aes-pub-shares]"
,
"[many-threads-crypto]"
,
"[many-threads-crypto-v2]"
,
"[aes-encrypt-decrypt]"
,
"[aes-dkg]"
"[aes-dkg]"
,
"[aes-dkg-v2]"
]
...
...
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