From 966328a70529ae2b7489626d5a2b817a3372362d Mon Sep 17 00:00:00 2001 From: kladko <13399135+kladkogex@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:03:26 +0200 Subject: [PATCH 1/3] SKALE-3422-use-blake-3 --- SkaleCommon.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SkaleCommon.h b/SkaleCommon.h index e3a37fb78..348830b5b 100644 --- a/SkaleCommon.h +++ b/SkaleCommon.h @@ -153,15 +153,13 @@ static const uint64_t MAX_CONSENSUS_HISTORY = 2 * MAX_ACTIVE_CONSENSUSES; static const uint64_t SESSION_KEY_CACHE_SIZE = 2; static const uint64_t SESSION_PUBLIC_KEY_CACHE_SIZE = 16; - - static constexpr uint64_t MAX_CATCHUP_DOWNLOAD_BYTES = 1000000000; static constexpr uint64_t PROPOSAL_HASHES_PER_DB = 100000; static constexpr uint64_t MAX_TRANSACTIONS_PER_BLOCK = 10000; -static constexpr int64_t EMPTY_BLOCK_INTERVAL_MS = 3000; +static constexpr int64_t EMPTY_BLOCK_INTERVAL_MS = 1; static constexpr uint64_t MIN_BLOCK_INTERVAL_MS = 1; @@ -175,7 +173,6 @@ static constexpr uint64_t WAIT_AFTER_NETWORK_ERROR_MS = 3000; static constexpr uint64_t CONNECTION_REFUSED_LOG_INTERVAL_MS = 10 * 60 * 1000; - // Non-tunable params static constexpr uint32_t SOCKET_BACKLOG = 64; @@ -303,7 +300,7 @@ static const uint64_t MAX_PROPOSAL_QUEUE_SIZE = 8; static const uint64_t SGX_SSL_PORT = 1026; -static const uint64_t BLOCK_PROPOSAL_RECEIVE_TIMEOUT_MS = 120000; +static const uint64_t BLOCK_PROPOSAL_RECEIVE_TIMEOUT_MS = 30000; static const uint64_t REBROADCAST_TIMEOUT_MS = 120000; From b5059a3d086ec6ddc05959eaf402d584e06fe095 Mon Sep 17 00:00:00 2001 From: kladko <13399135+kladkogex@users.noreply.github.com> Date: Thu, 29 Oct 2020 17:05:12 +0200 Subject: [PATCH 2/3] SKALE-3422-use-blake-3 --- network/Buffer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/network/Buffer.cpp b/network/Buffer.cpp index 768c4f7b0..fa431979a 100644 --- a/network/Buffer.cpp +++ b/network/Buffer.cpp @@ -61,7 +61,6 @@ Buffer::Buffer(size_t _size) { } this->size = _size; buf = make_shared>(size); - std::fill(buf->begin(), buf->end(), 0); } size_t Buffer::getSize() const { From 61a261b454af2d11d2550ff8cef05a40c54adcd2 Mon Sep 17 00:00:00 2001 From: kladko <13399135+kladkogex@users.noreply.github.com> Date: Thu, 29 Oct 2020 17:08:17 +0200 Subject: [PATCH 3/3] SKALE-3422-use-blake-3 --- crypto/SHAHash.cpp | 119 --------------------------------------------- crypto/SHAHash.h | 62 ----------------------- 2 files changed, 181 deletions(-) delete mode 100644 crypto/SHAHash.cpp delete mode 100644 crypto/SHAHash.h diff --git a/crypto/SHAHash.cpp b/crypto/SHAHash.cpp deleted file mode 100644 index 780e914bd..000000000 --- a/crypto/SHAHash.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - Copyright (C) 2019 SKALE Labs - - This file is part of skale-consensus. - - skale-consensus is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - skale-consensus is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with skale-consensus. If not, see . - - @file SHAHash.cpp - @author Stan Kladko - @date 2019 -*/ - -#include "SkaleCommon.h" -#include "Log.h" -#include "thirdparty/json.hpp" - - -#include "network/Utils.h" -#include "exceptions/InvalidArgumentException.h" - -#include "SHAHash.h" - -void SHAHash::print() { - CHECK_STATE(hash); - for (size_t i = 0; i < SHA_HASH_LEN; i++) { - cerr << to_string(hash->at(i)); - } -} - - -uint8_t SHAHash::at(uint32_t _position) { - CHECK_STATE(hash); - return hash->at(_position); -} - - -ptr SHAHash::fromHex(const string& _hex) { - CHECK_ARGUMENT(_hex != ""); - auto result = make_shared>(); - Utils::cArrayFromHex(_hex, result->data(), SHA_HASH_LEN); - return make_shared(result); -} - -string SHAHash::toHex() { - CHECK_STATE(hash); - auto result = Utils::carray2Hex(hash->data(), SHA_HASH_LEN); - CHECK_STATE(result != ""); - return result; -} - - -int SHAHash::compare(const ptr& _hash2 ) { - CHECK_ARGUMENT( _hash2 ); - CHECK_STATE(hash); - - for (size_t i = 0; i < SHA_HASH_LEN; i++) { - if (hash->at(i) < _hash2->at(i)) - return -1; - if (hash->at(i) > _hash2->at(i)) - return 1; - } - return 0; -} - -SHAHash::SHAHash(const ptr>& _hash) { - CHECK_ARGUMENT(_hash); - hash = _hash; -} - -ptr SHAHash::calculateHash(const ptr>& _data) { - CHECK_ARGUMENT(_data); - auto digest = make_shared >(); - - CryptoPP::SHA256 hashObject; - - hashObject.Update(_data->data(), _data->size()); - hashObject.Final(digest->data()); - - auto hash = make_shared(digest); - return hash; -} - -ptr SHAHash::merkleTreeMerge(const ptr& _left, const ptr& _right) { - CHECK_ARGUMENT(_left); - CHECK_ARGUMENT(_right); - - auto concatenation = make_shared>(); - concatenation->reserve(2 * SHA_HASH_LEN); - - auto leftHash = _left->getHash(); - CHECK_STATE(leftHash); - - concatenation->insert(concatenation->end(), leftHash->begin(), leftHash->end()); - - auto rightHash = _right->getHash(); - CHECK_STATE(rightHash); - - concatenation->insert(concatenation->end(), rightHash->begin(), rightHash->end()); - - return calculateHash(concatenation); -} - -ptr> SHAHash::getHash() const { - CHECK_STATE(hash); - return hash; -} - - diff --git a/crypto/SHAHash.h b/crypto/SHAHash.h deleted file mode 100644 index bd320643a..000000000 --- a/crypto/SHAHash.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (C) 2019 SKALE Labs - - This file is part of skale-consensus. - - skale-consensus is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - skale-consensus is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with skale-consensus. If not, see . - - @file SHAHash.h - @author Stan Kladko - @date 2019 -*/ - -#ifndef CONSENSUS_SHAHASH_H -#define CONSENSUS_SHAHASH_H - - -#define HASH_UPDATE(__HASH__, __OBJECT__) __HASH__.Update(reinterpret_cast < uint8_t * > ( &__OBJECT__), sizeof(__OBJECT__)) - -class SHAHash { - - ptr> hash; - -public: - - explicit SHAHash(const ptr>& _hash); - - - void print(); - - uint8_t at(uint32_t _position); - - int compare(const ptr& _hash2 ); - - uint8_t * data() { - return hash->data(); - }; - - ptr> getHash() const; - - static ptr fromHex(const string& _hex); - - string toHex(); - - static ptr calculateHash(const ptr>& _data); - - static ptr merkleTreeMerge(const ptr& _left, const ptr& _right); - -}; - - -#endif //CONSENSUS_SHA3HASH_H