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
2259ae3d
Unverified
Commit
2259ae3d
authored
Oct 15, 2020
by
Oleh Nikolaiev
Committed by
GitHub
Oct 15, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #192 from skalenetwork/bug/SKALE-3346-cleanup-macros
Bug/skale 3346 cleanup macros
parents
e075e5eb
8a3cdb12
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
90 additions
and
40 deletions
+90
-40
DKGCrypto.cpp
DKGCrypto.cpp
+31
-5
DKGCrypto.h
DKGCrypto.h
+3
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+32
-13
SGXWalletServer.hpp
SGXWalletServer.hpp
+2
-2
abstractstubserver.h
abstractstubserver.h
+3
-3
common.h
common.h
+1
-1
docker-compose.yml
run_sgx/docker-compose.yml
+1
-1
publish_image.sh
scripts/publish_image.sh
+2
-8
secure_enclave.c
secure_enclave/secure_enclave.c
+1
-1
stubclient.h
stubclient.h
+3
-1
testw.cpp
testw.cpp
+11
-4
No files found.
DKGCrypto.cpp
View file @
2259ae3d
...
...
@@ -152,9 +152,11 @@ string gen_dkg_poly(int _t) {
return
result
;
}
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
)
{
vector
<
vector
<
string
>>
get_verif_vect
(
const
string
&
encryptedPolyHex
,
int
t
,
int
n
)
{
CHECK_STATE
(
encryptedPolyHex
);
auto
encryptedPolyHexPtr
=
encryptedPolyHex
.
c_str
();
CHECK_STATE
(
encryptedPolyHexPtr
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
...
...
@@ -166,7 +168,7 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
vector
<
uint8_t
>
encrDKGPoly
(
2
*
BUF_LEN
,
0
);
if
(
!
hex2carray
(
encryptedPolyHex
,
&
encLen
,
encrDKGPoly
.
data
(),
6100
))
{
if
(
!
hex2carray
(
encryptedPolyHex
Ptr
,
&
encLen
,
encrDKGPoly
.
data
(),
6100
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
...
...
@@ -182,15 +184,39 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
vector
<
string
>
g2Strings
=
splitString
(
pubShares
.
data
(),
','
);
vector
<
vector
<
string
>>
pubSharesVect
;
vector
<
vector
<
string
>>
pubSharesVect
(
t
)
;
for
(
uint64_t
i
=
0
;
i
<
g2Strings
.
size
();
i
++
)
{
vector
<
string
>
coeffStr
=
splitString
(
g2Strings
.
at
(
i
).
c_str
(),
':'
);
pubSharesVect
.
push_back
(
coeffStr
)
;
pubSharesVect
[
i
]
=
coeffStr
;
}
return
pubSharesVect
;
}
vector
<
vector
<
string
>>
getVerificationVectorMult
(
const
std
::
string
&
encryptedPolyHex
,
int
t
,
int
n
,
size_t
ind
)
{
auto
verificationVector
=
get_verif_vect
(
encryptedPolyHex
,
t
,
n
);
vector
<
vector
<
string
>>
result
(
t
);
for
(
size_t
i
=
0
;
i
<
t
;
++
i
)
{
libff
::
alt_bn128_G2
current_coefficient
;
current_coefficient
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
0
].
c_str
());
current_coefficient
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
1
].
c_str
());
current_coefficient
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
2
].
c_str
());
current_coefficient
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
3
].
c_str
());
current_coefficient
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
current_coefficient
=
libff
::
power
(
libff
::
alt_bn128_Fr
(
ind
+
1
),
i
)
*
current_coefficient
;
current_coefficient
.
to_affine_coordinates
();
auto
g2_str
=
convertG2ToString
(
current_coefficient
);
result
[
i
]
=
splitString
(
g2_str
.
c_str
(),
':'
);
}
return
result
;
}
string
getSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>
&
_publicKeys
,
int
_t
,
...
...
DKGCrypto.h
View file @
2259ae3d
...
...
@@ -33,7 +33,9 @@ using namespace std;
string
gen_dkg_poly
(
int
_t
);
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
);
vector
<
vector
<
string
>>
get_verif_vect
(
const
string
&
encryptedPolyHex
,
int
t
,
int
n
);
vector
<
vector
<
string
>>
getVerificationVectorMult
(
const
std
::
string
&
encryptedPolyHex
,
int
t
,
int
n
,
size_t
ind
);
vector
<
string
>
splitString
(
const
char
*
coeffs
,
const
char
symbol
);
...
...
SGXWalletServer.cpp
View file @
2259ae3d
...
...
@@ -149,7 +149,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
int
numThreads
=
64
;
#if
SGX_MODE ==
SIM
#if
def SGX_HW_
SIM
numThreads
=
16
;
#endif
...
...
@@ -193,7 +193,16 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
throw
SGXException
(
INVALID_BLS_NAME
,
"Invalid BLS key name"
);
}
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
_keyShare
.
c_str
());
string
hashTmp
=
_keyShare
;
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
2
);
}
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid BLS key share, please use hex"
);
}
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
hashTmp
.
c_str
());
if
(
errStatus
!=
0
)
{
throw
SGXException
(
errStatus
,
errMsg
.
data
());
...
...
@@ -388,7 +397,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
verifVector
=
get_verif_vect
(
encrPoly
->
c_str
()
,
_t
,
_n
);
verifVector
=
get_verif_vect
(
*
encrPoly
,
_t
,
_n
);
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
vector
<
string
>
currentCoef
=
verifVector
.
at
(
i
);
...
...
@@ -586,7 +595,7 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value& pu
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
)
{
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_
t
,
int
_n
,
int
_
ind
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -603,13 +612,23 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
result
[
"share*G2"
]
=
*
shareG2_ptr
;
result
[
"dhKey"
]
=
DHKey
;
// TODO: delete dh keys
// for (int i = 0; i < _n; i++) {
// string name = _polyName + "_" + to_string(i) + ":";
// LevelDB::getLevelDb()->deleteDHDKGKey(name);
// string shareG2_name = "shareG2_" + _polyName + "_" + to_string(i) + ":";
// LevelDB::getLevelDb()->deleteKey(shareG2_name);
// }
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
auto
verificationVectorMult
=
getVerificationVectorMult
(
encrPoly
->
c_str
(),
_t
,
_n
,
_ind
);
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
vector
<
string
>
currentCoef
=
verificationVectorMult
.
at
(
i
);
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
result
[
"verificationVectorMult"
][
i
][
j
]
=
currentCoef
.
at
(
j
);
}
}
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
string
encryptedSecretShareName
=
"encryptedSecretShare:"
+
_polyName
;
...
...
@@ -737,8 +756,8 @@ Json::Value SGXWalletServer::blsSignMessageHash(const string &_keyShareName, con
return
blsSignMessageHashImpl
(
_keyShareName
,
_messageHash
,
_t
,
_n
);
}
Json
::
Value
SGXWalletServer
::
complaintResponse
(
const
string
&
polyName
,
int
ind
)
{
return
complaintResponseImpl
(
polyName
,
ind
);
Json
::
Value
SGXWalletServer
::
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
{
return
complaintResponseImpl
(
polyName
,
t
,
n
,
ind
);
}
Json
::
Value
SGXWalletServer
::
multG2
(
const
string
&
x
)
{
...
...
SGXWalletServer.hpp
View file @
2259ae3d
...
...
@@ -76,7 +76,7 @@ public:
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
ind
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
ind
);
virtual
Json
::
Value
multG2
(
const
string
&
x
);
...
...
@@ -126,7 +126,7 @@ public:
static
Json
::
Value
calculateAllBLSPublicKeysImpl
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
static
Json
::
Value
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
);
static
Json
::
Value
complaintResponseImpl
(
const
string
&
_polyName
,
int
t
,
int
n
,
int
_ind
);
static
Json
::
Value
multG2Impl
(
const
string
&
_x
);
...
...
abstractstubserver.h
View file @
2259ae3d
...
...
@@ -50,7 +50,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"createBLSPrivateKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
"ethKeyName"
,
jsonrpc
::
JSON_STRING
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"secretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
createBLSPrivateKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getBLSPublicKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getBLSPublicKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"calculateAllBLSPublicKeys"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"publicShares"
,
jsonrpc
::
JSON_ARRAY
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
calculateAllBLSPublicKeysI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"complaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
complaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"complaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"
t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"
ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
complaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"multG2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"x"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
multG2I
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"isPolyExists"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
isPolyExistsI
);
...
...
@@ -111,7 +111,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
}
inline
virtual
void
complaintResponseI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
complaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"ind"
].
asInt
());
response
=
this
->
complaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"
t"
].
asInt
(),
request
[
"n"
].
asInt
(),
request
[
"
ind"
].
asInt
());
}
inline
virtual
void
multG2I
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
...
...
@@ -152,7 +152,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
createBLSPrivateKey
(
const
std
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
std
::
string
&
blsKeyName
)
=
0
;
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
=
0
;
virtual
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
=
0
;
virtual
Json
::
Value
multG2
(
const
std
::
string
&
x
)
=
0
;
virtual
Json
::
Value
isPolyExists
(
const
std
::
string
&
polyName
)
=
0
;
...
...
common.h
View file @
2259ae3d
...
...
@@ -101,7 +101,7 @@ BOOST_THROW_EXCEPTION(runtime_error(__ERR_STRING__)); \
extern
std
::
shared_timed_mutex
initMutex
;
extern
uint64_t
initTime
;
#if
SGX_MODE ==
SIM
#if
def SGX_HW_
SIM
#define ENCLAVE_RESTART_PERIOD_S 5
#else
#define ENCLAVE_RESTART_PERIOD_S 60 * 10
...
...
run_sgx/docker-compose.yml
View file @
2259ae3d
version
:
'
3'
services
:
sgxwallet
:
image
:
skalenetwork/sgxwallet:latest
image
:
skalenetwork/sgxwallet
_signed
:latest
restart
:
always
ports
:
-
"
1026:1026"
...
...
scripts/publish_image.sh
View file @
2259ae3d
...
...
@@ -10,14 +10,8 @@ CONTAINER_NAME=$1
REPO_NAME
=
skalenetwork/
$CONTAINER_NAME
IMAGE_NAME
=
$REPO_NAME
:
$VERSION
if
[
"
${
BRANCH
}
"
=
"stable"
]
;
then
LATEST_IMAGE_NAME
=
$REPO_NAME
:latest
docker tag
"
${
IMAGE_NAME
}
"
"
${
LATEST_IMAGE_NAME
}
"
else
LATEST_IMAGE_NAME
=
$REPO_NAME
:
$BRANCH
-latest
docker tag
"
${
IMAGE_NAME
}
"
"
${
LATEST_IMAGE_NAME
}
"
fi
LATEST_IMAGE_NAME
=
$REPO_NAME
:
$BRANCH
-latest
docker tag
"
${
IMAGE_NAME
}
"
"
${
LATEST_IMAGE_NAME
}
"
:
"
${
DOCKER_USERNAME
?Need to set DOCKER_USERNAME
}
"
:
"
${
DOCKER_PASSWORD
?Need to set DOCKER_PASSWORD
}
"
...
...
secure_enclave/secure_enclave.c
View file @
2259ae3d
...
...
@@ -163,7 +163,7 @@ void trustedEnclaveInit(uint64_t _logLevel) {
LOG_INFO
(
"SECURITY WARNING: sgxwallet is running in INSECURE DEBUG MODE! NEVER USE IN PRODUCTION!"
);
#endif
#if
SGX_MODE ==
SIM
#if
def SGX_HW_
SIM
LOG_INFO
(
"SECURITY WARNING: sgxwallet is running in INSECURE SIMULATION MODE! NEVER USE IN PRODUCTION!"
);
#endif
...
...
stubclient.h
View file @
2259ae3d
...
...
@@ -171,10 +171,12 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
{
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"t"
]
=
t
;
p
[
"n"
]
=
n
;
p
[
"ind"
]
=
ind
;
Json
::
Value
result
=
this
->
CallMethod
(
"complaintResponse"
,
p
);
if
(
result
.
isObject
())
...
...
testw.cpp
View file @
2259ae3d
...
...
@@ -439,13 +439,20 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
TEST_CASE_METHOD
(
TestFixture
,
"Delete Bls Key"
,
"[delete-bls-key]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
std
::
string
name
=
"BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0"
;
libff
::
alt_bn128_Fr
key
=
libff
::
alt_bn128_Fr
(
"6507625568967977077291849236396320012317305261598035438182864059942098934847"
);
std
::
string
key_str
=
TestUtils
::
stringFromFr
(
key
);
PRINT_SRC_LINE
c
.
importBLSKeyShare
(
key_str
,
name
);
PRINT_SRC_LINE
auto
response
=
c
.
importBLSKeyShare
(
key_str
,
name
);
REQUIRE
(
response
[
"status"
]
!=
0
);
key_str
=
"0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"
;
response
=
c
.
importBLSKeyShare
(
key_str
,
name
);
REQUIRE
(
response
[
"status"
]
==
0
);
REQUIRE
(
c
.
blsSignMessageHash
(
name
,
SAMPLE_HASH
,
1
,
1
)[
"status"
]
==
0
);
REQUIRE
(
c
.
deleteBlsKey
(
name
)[
"deleted"
]
==
true
);
}
...
...
@@ -643,7 +650,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
REQUIRE
(
res
);
}
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
0
);
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
...
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