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
970855e0
Unverified
Commit
970855e0
authored
Nov 17, 2020
by
Stan Kladko
Committed by
GitHub
Nov 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #221 from skalenetwork/bug/SKALE-3481-nightly
Bug/Skale-3481 added nightly tests and fixed a memory leak
parents
3f490811
19a4e0f9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
66 deletions
+121
-66
nightlytests.yml
.github/workflows/nightlytests.yml
+20
-0
DKGCrypto.cpp
DKGCrypto.cpp
+6
-4
SGXWalletServer.cpp
SGXWalletServer.cpp
+8
-1
TestUtils.cpp
TestUtils.cpp
+46
-12
docker_test.py
scripts/docker_test.py
+27
-25
secure_enclave.c
secure_enclave/secure_enclave.c
+7
-17
secure_enclave.config.xml.sim
secure_enclave/secure_enclave.config.xml.sim
+5
-5
testw.cpp
testw.cpp
+1
-1
testw.py
testw.py
+1
-1
No files found.
.github/workflows/nightlytests.yml
0 → 100644
View file @
970855e0
name
:
Build, test and push sim mode container
on
:
schedule
:
-
cron
:
"
*/10
*
*
*
*"
jobs
:
build
:
runs-on
:
ubuntu-18.04
env
:
DOCKER_USERNAME
:
${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
steps
:
-
uses
:
actions/checkout@v1
-
name
:
submodule update
run
:
git submodule update --init --recursive
-
name
:
build container for testing
run
:
python3 scripts/docker_build.py DockerfileSimulation sgxwalletsim ${GITHUB_SHA}
-
name
:
test
run
:
python3 scripts/docker_test.py DockerfileSimulation sgxwalletsim
DKGCrypto.cpp
View file @
970855e0
...
...
@@ -67,10 +67,9 @@ string ConvertToString(T field_elem, int base = 10) {
SAFE_CHAR_BUF
(
arr
,
mpz_sizeinbase
(
t
,
base
)
+
2
);
mpz_get_str
(
arr
,
base
,
t
);
mpz_clear
(
t
);
mpz_clear
(
t
);
string
output
=
arr
;
return
output
;
}
...
...
@@ -82,8 +81,7 @@ string convertHexToDec(const string &hex_str) {
try
{
if
(
mpz_set_str
(
dec
,
hex_str
.
c_str
(),
16
)
==
-
1
)
{
mpz_clear
(
dec
);
return
ret
;
goto
clean
;
}
SAFE_CHAR_BUF
(
arr
,
mpz_sizeinbase
(
dec
,
10
)
+
2
);
...
...
@@ -97,6 +95,10 @@ string convertHexToDec(const string &hex_str) {
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
}
clean
:
mpz_clear
(
dec
);
return
ret
;
}
...
...
SGXWalletServer.cpp
View file @
970855e0
...
...
@@ -121,6 +121,9 @@ void SGXWalletServer::printDB() {
int
SGXWalletServer
::
initHttpsServer
(
bool
_checkCerts
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
spdlog
::
info
(
"Initing server, number of threads: {}"
,
NUM_THREADS
);
string
rootCAPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/rootCA.pem"
;
string
keyCAPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/rootCA.key"
;
...
...
@@ -542,6 +545,8 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
CHECK_STATE
(
encryptedKeyHex_ptr
);
bool
res
=
createBLSShare
(
_blsKeyName
,
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
if
(
res
)
{
spdlog
::
info
(
"BLS KEY SHARE CREATED "
);
...
...
@@ -549,6 +554,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
throw
SGXException
(
-
122
,
"Error while creating BLS key share"
);
}
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
...
...
@@ -557,6 +563,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
}
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
string
encryptedSecretShareName
=
"encryptedSecretShare:"
+
_polyName
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
encryptedSecretShareName
);
...
...
@@ -845,9 +852,9 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_
}
void
SGXWalletServer
::
writeDataToDB
(
const
string
&
name
,
const
string
&
value
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
name
)
!=
nullptr
)
{
throw
SGXException
(
KEY_NAME_ALREADY_EXISTS
,
"Name already exists"
);
}
LevelDB
::
getLevelDb
()
->
writeString
(
name
,
value
);
}
TestUtils.cpp
View file @
970855e0
...
...
@@ -79,14 +79,12 @@ string TestUtils::convertDecToHex(string dec, int numBytes) {
mpz_t
num
;
mpz_init
(
num
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
vector
<
char
>
tmp
(
mpz_sizeinbase
(
num
,
16
)
+
2
,
0
);
char
*
hex
=
mpz_get_str
(
tmp
.
data
(),
16
,
num
);
string
result
=
hex
;
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
result
.
insert
(
0
,
n_zeroes
,
'0'
);
mpz_clear
(
num
);
return
result
;
}
...
...
@@ -176,22 +174,44 @@ void TestUtils::sendRPCRequest() {
int
schainID
=
counter
.
fetch_add
(
1
);
int
dkgID
=
counter
.
fetch_add
(
1
);
int
testCount
=
1
;
if
(
getenv
(
"NIGHTLY_TESTS"
))
{
testCount
=
10
;
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
usleep
(
100000
);
ethKeys
[
i
]
=
c
.
generateECDSAKey
();
for
(
int
i2
=
0
;
i2
<
testCount
;
i2
++
)
{
auto
keyName
=
ethKeys
[
i
][
"keyName"
].
asString
();
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
16
,
keyName
,
SAMPLE_HASH
);
CHECK_STATE
(
sig
[
"status"
].
asInt
()
==
0
);
}
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
);
for
(
int
i3
=
0
;
i3
<=
testCount
;
i3
++
)
{
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
);
usleep
(
100000
);
for
(
int
i4
=
0
;
i4
<=
testCount
;
i4
++
)
{
secretShares
[
i
]
=
c
.
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
();
...
...
@@ -206,8 +226,12 @@ void TestUtils::sendRPCRequest() {
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
.
dkgVerification
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
verif
[
"status"
]
==
0
);
usleep
(
100000
);
for
(
int
i5
=
0
;
i5
<=
testCount
;
i5
++
)
{
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
verif
[
"status"
]
==
0
);
}
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
...
@@ -227,17 +251,27 @@ void TestUtils::sendRPCRequest() {
publicShares
[
"publicShares"
][
i
]
=
pubShares
[
i
];
}
Json
::
Value
blsPublicKeys
=
c
.
calculateAllBLSPublicKeys
(
publicShares
,
t
,
n
);
CHECK_STATE
(
blsPublicKeys
[
"status"
]
==
0
);
Json
::
Value
blsPublicKeys
;
for
(
int
i6
=
0
;
i6
<=
testCount
;
i6
++
)
{
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
);
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
);
for
(
int
i7
=
0
;
i7
<=
testCount
;
i7
++
)
{
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
()),
...
...
scripts/docker_test.py
View file @
970855e0
...
...
@@ -29,23 +29,27 @@ topDir = os.getcwd() + "/sgxwallet"
print
(
"Starting container test"
)
print
(
"Top directory is:"
+
topDir
)
DOCKER_FILE_NAME
=
sys
.
argv
[
1
]
;
DOCKER_FILE_NAME
=
sys
.
argv
[
1
]
IMAGE_NAME
=
sys
.
argv
[
2
]
TAG_POSTFIX
=
"latest_commit"
FULL_IMAGE_NAME
=
"skalenetwork/"
+
IMAGE_NAME
+
":"
+
TAG_POSTFIX
;
FULL_IMAGE_NAME
=
"skalenetwork/"
+
IMAGE_NAME
+
":"
+
TAG_POSTFIX
print
(
"Running tests"
);
dockerRun
=
subprocess
.
run
([
"docker"
,
"run"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-t"
,
isNightly
=
os
.
environ
.
get
(
"NIGHTLY_TESTS"
)
if
isNightly
:
dockerRun
=
subprocess
.
run
([
"docker"
,
"run"
,
"-e"
,
"NIGHTLY_TESTS='1'"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-t"
,
"-v"
,
"/dev/urandom:/dev/random"
,
"--name"
,
"sgxwallet"
,
"--network=host"
,
"skalenetwork/"
+
IMAGE_NAME
+
":"
+
TAG_POSTFIX
,
"-t"
])
else
:
dockerRun
=
subprocess
.
run
([
"docker"
,
"run"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-t"
,
"-v"
,
"/dev/urandom:/dev/random"
,
"--name"
,
"sgxwallet"
,
"--network=host"
,
"skalenetwork/"
+
IMAGE_NAME
+
":"
+
TAG_POSTFIX
,
"-t"
])
print
(
dockerRun
.
stdout
)
print
(
dockerRun
.
stderr
)
assert
dockerRun
.
returncode
==
0
;
assert
subprocess
.
call
([
"docker"
,
"rm"
,
"sgxwallet"
])
==
0
assert
subprocess
.
call
([
"docker"
,
"run"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-d"
,
"--name"
,
"sgxwallet"
,
...
...
@@ -53,25 +57,23 @@ assert subprocess.call(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/
time
.
sleep
(
5
);
#
#
#assert os.path.isdir(topDir + '/sgx_data/sgxwallet.db')
#assert os.path.isdir(topDir + '/sgx_data/cert_data');
#assert os.path.isdir(topDir + '/sgx_data/CSR_DB');
#assert os.path.isdir(topDir + '/sgx_data/CSR_STATUS_DB');
#assert os.path.isfile(topDir + '/sgx_data/cert_data/SGXServerCert.crt')
#assert os.path.isfile(topDir + '/sgx_data/cert_data/SGXServerCert.key')
#assert os.path.isfile(topDir + '/sgx_data/cert_data/rootCA.pem')
#assert os.path.isfile(topDir + '/sgx_data/cert_data/rootCA.key')
assert
os
.
path
.
isdir
(
topDir
+
'/sgx_data/sgxwallet.db'
)
assert
os
.
path
.
isdir
(
topDir
+
'/sgx_data/cert_data'
);
assert
os
.
path
.
isdir
(
topDir
+
'/sgx_data/CSR_DB'
);
assert
os
.
path
.
isdir
(
topDir
+
'/sgx_data/CSR_STATUS_DB'
);
assert
os
.
path
.
isfile
(
topDir
+
'/sgx_data/cert_data/SGXServerCert.crt'
)
assert
os
.
path
.
isfile
(
topDir
+
'/sgx_data/cert_data/SGXServerCert.key'
)
assert
os
.
path
.
isfile
(
topDir
+
'/sgx_data/cert_data/rootCA.pem'
)
assert
os
.
path
.
isfile
(
topDir
+
'/sgx_data/cert_data/rootCA.key'
)
#
s1 = socket.socket()
#
s2 = socket.socket()
#
s3 = socket.socket()
#
address = '127.0.0.1'
#
s1.connect((address, 1026))
#
s2.connect((address, 1027))
#
s3.connect((address, 1028))
s1
=
socket
.
socket
()
s2
=
socket
.
socket
()
s3
=
socket
.
socket
()
address
=
'127.0.0.1'
s1
.
connect
((
address
,
1026
))
s2
.
connect
((
address
,
1027
))
s3
.
connect
((
address
,
1028
))
#
s1.close()
#
s2.close()
#
s3.close()
s1
.
close
()
s2
.
close
()
s3
.
close
()
secure_enclave/secure_enclave.c
View file @
970855e0
...
...
@@ -507,15 +507,6 @@ void trustedGetPublicEcdsaKey(int *errStatus, char *errString,
point_clear
(
pKey
);
point_clear
(
pKey_test
);
static
uint64_t
counter
=
0
;
if
(
counter
%
1000
==
0
)
{
LOG_INFO
(
__FUNCTION__
);
LOG_INFO
(
"Thousand SGX calls completed"
);
}
counter
++
;
}
static
uint64_t
sigCounter
=
0
;
...
...
@@ -537,7 +528,8 @@ void trustedEcdsaSign(int *errStatus, char *errString, uint8_t *encryptedPrivate
mpz_init
(
privateKeyMpz
);
mpz_t
msgMpz
;
mpz_init
(
msgMpz
);
signature
sign
=
signature_init
();
signature
sign
=
NULL
;
sign
=
signature_init
();
uint8_t
type
=
0
;
uint8_t
exportable
=
0
;
...
...
@@ -603,7 +595,8 @@ void trustedEcdsaSign(int *errStatus, char *errString, uint8_t *encryptedPrivate
mpz_clear
(
privateKeyMpz
);
mpz_clear
(
msgMpz
);
signature_free
(
sign
);
if
(
sign
)
signature_free
(
sign
);
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
"SGX call completed"
);
}
...
...
@@ -1139,12 +1132,9 @@ trustedGetBlsPubKey(int *errStatus, char *errString, uint8_t *encryptedPrivateKe
CHECK_STATUS
(
"could not calculate bls public key"
);
SET_SUCCESS
static
uint64_t
counter
=
0
;
clean:
if
(
counter
%
1000
==
0
)
{
LOG_INFO
(
__FUNCTION__
);
LOG_INFO
(
"Thousand SGX calls completed"
);
}
;
counter
++
;
}
secure_enclave/secure_enclave.config.xml.sim
View file @
970855e0
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>1</ISVSVN>
<StackMaxSize>0x
10
00000</StackMaxSize>
<HeapMaxSize>0x
10
00000</HeapMaxSize>
<TCSNum>
16
</TCSNum>
<TCSMaxNum>
16
</TCSMaxNum>
<TCSMinPool>
16
</TCSMinPool>
<StackMaxSize>0x
2
00000</StackMaxSize>
<HeapMaxSize>0x
2
00000</HeapMaxSize>
<TCSNum>
20
</TCSNum>
<TCSMaxNum>
20
</TCSMaxNum>
<TCSMinPool>
20
</TCSMinPool>
<TCSPolicy>0</TCSPolicy>
<!-- Recommend changing 'DisableDebug' to 1 to make the enclave undebuggable for enclave release -->
<DisableDebug>0</DisableDebug>
...
...
testw.cpp
View file @
970855e0
...
...
@@ -781,7 +781,7 @@ TEST_CASE_METHOD(TestFixture, "AES encrypt/decrypt", "[aes-encrypt-decrypt]") {
TEST_CASE_METHOD
(
TestFixture
,
"Many threads ecdsa dkg bls"
,
"[many-threads-crypto]"
)
{
vector
<
thread
>
threads
;
int
num_threads
=
4
;
int
num_threads
=
16
;
for
(
int
i
=
0
;
i
<
num_threads
;
i
++
)
{
threads
.
push_back
(
thread
(
TestUtils
::
sendRPCRequest
));
}
...
...
testw.py
View file @
970855e0
...
...
@@ -30,6 +30,7 @@ topDir = os.getcwd() + "/sgxwallet"
print
(
"Top directory is:"
+
topDir
)
testList
=
[
"[first-run]"
,
"[second-run]"
,
"[many-threads-crypto]"
,
"[backup-restore]"
,
"[cert-sign]"
,
"[get-server-status]"
,
...
...
@@ -48,7 +49,6 @@ testList = ["[first-run]",
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
"[dkg-aes-pub-shares]"
,
"[many-threads-crypto]"
,
"[aes-encrypt-decrypt]"
,
"[aes-dkg]"
]
...
...
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