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
09e8c990
Unverified
Commit
09e8c990
authored
Jun 16, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2678-BLS-test-vectors
parent
f8c7f7db
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
154 deletions
+160
-154
TestUtils.cpp
TestUtils.cpp
+152
-0
TestUtils.h
TestUtils.h
+5
-0
testw.cpp
testw.cpp
+3
-154
No files found.
TestUtils.cpp
View file @
09e8c990
...
...
@@ -273,3 +273,155 @@ void TestUtils::destroyEnclave() {
}
}
void
TestUtils
::
doDKG
(
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
.
getSecretShare
(
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
.
dkgVerification
(
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
.
dkgVerification
(
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
()))
{
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
,
i
+
1
);
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
;
}
\ No newline at end of file
TestUtils.h
View file @
09e8c990
...
...
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <jsonrpccpp/client/connectors/httpclient.h>
#include <sgx_tcrypto.h>
#include "stubclient.h"
using
namespace
std
;
...
...
@@ -51,6 +52,10 @@ public:
static
void
sendRPCRequest
();
static
void
destroyEnclave
();
static
void
doDKG
(
StubClient
&
c
,
int
n
,
int
t
,
vector
<
string
>&
_ecdsaKeyNames
,
vector
<
string
>&
_blsKeyNames
,
int
schainID
,
int
dkgID
);
};
#endif //SGXWALLET_TESTW_H
testw.cpp
View file @
09e8c990
...
...
@@ -68,7 +68,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SEKManager.h"
#include <thread>
#include "common.h"
#include "stubclient.h"
#include "SGXRegistrationServer.h"
#include "SGXWalletServer.h"
#include "sgxwallet.h"
...
...
@@ -536,159 +536,8 @@ TEST_CASE_METHOD(TestFixture, "DKG AES encrypted secret shares test", "[dkg-aes-
void
doDKG
(
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
);
REQUIRE
(
verifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
ethKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShare
(
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
.
dkgVerification
(
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
.
dkgVerification
(
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
()))
{
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
,
i
+
1
);
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
;
}
TEST_CASE_METHOD
(
TestFixture
,
"DKG_BLS test"
,
"[dkg-bls]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
...
...
@@ -700,7 +549,7 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
int
schainID
=
TestUtils
::
randGen
();
int
dkgID
=
TestUtils
::
randGen
();
doDKG
(
c
,
4
,
1
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
TestUtils
::
doDKG
(
c
,
4
,
1
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
REQUIRE
(
blsKeyNames
.
size
()
==
4
);
...
...
@@ -708,7 +557,7 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
schainID
=
TestUtils
::
randGen
();
dkgID
=
TestUtils
::
randGen
();
doDKG
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
TestUtils
::
doDKG
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
}
...
...
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