Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions AgentDocs/Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SuperGenius/
│ ├── blockchain/ # BlockTree, BlockStorage, BlockHeaderRepository
│ ├── coinprices/ # CoinGecko price retriever
│ ├── crdt/ # CRDT datastore, GlobalDB, PubSub broadcaster
│ ├── crypto/ # ED25519, SR25519, Secp256k1, BIP39, VRF, Hasher
│ ├── crypto/ # ED25519, SR25519, Secp256k1, BIP39, VRF, hash helpers
│ ├── local_secure_storage/ # Platform-specific encrypted key storage
│ ├── macro/ # Utility macros
│ ├── outcome/ # outcome::result<T> adapter
Expand Down Expand Up @@ -497,8 +497,7 @@ TransferProofProto { BaseProofData proof_data; TransferProofPublicInputs public_
| `VRFProviderImpl` | class | Concrete VRF (Ristretto-VRF). |
| `VRFOutput` | struct | VRF output bytes + proof bytes. |
| `VRFVerifyOutput` | struct | VRF verification result + output. |
| `Hasher` | interface | Multi-algorithm hash (blake2b-256/512, keccak, sha2, twox). |
| `HasherImpl` | class | Concrete hasher. |
| Hash helpers | free functions | Multi-algorithm hashing (blake2b, keccak, sha2, twox). |
| `CryptoStore` | interface | Key store: list, generate, get keypairs by key type. |
| `CryptoStoreImpl` | class | Concrete in-memory + file-backed key store. |
| `Bip39Provider` | interface | BIP39 mnemonic generation and seed derivation. |
Expand Down
11 changes: 4 additions & 7 deletions src/account/AccountMessenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <type_traits>
#include "AccountMessenger.hpp"
#include "base/sgns_version.hpp"
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"
#include "primitives/cid/cid.hpp"

OUTCOME_CPP_DEFINE_CATEGORY_3( sgns, AccountMessenger::Error, e )
Expand Down Expand Up @@ -1023,8 +1023,7 @@ namespace sgns
uint64_t random_value = gen();

std::string to_hash = address_ + std::to_string( random_value );
sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( to_hash.data(), to_hash.size() );
auto hash = sgns::crypto::sha2_256( to_hash.data(), to_hash.size() );

uint64_t req_id = 0;
std::memcpy( &req_id, hash.data(), sizeof( req_id ) );
Expand Down Expand Up @@ -1139,8 +1138,7 @@ namespace sgns
uint64_t random_value = gen();

std::string to_hash = address_ + std::to_string( random_value );
sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( to_hash.data(), to_hash.size() );
auto hash = sgns::crypto::sha2_256( to_hash.data(), to_hash.size() );

uint64_t req_id = 0;
std::memcpy( &req_id, hash.data(), sizeof( req_id ) );
Expand Down Expand Up @@ -1266,8 +1264,7 @@ namespace sgns
uint64_t random_value = gen();

std::string to_hash = address_ + std::to_string( random_value );
sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( to_hash.data(), to_hash.size() );
auto hash = sgns::crypto::sha2_256( to_hash.data(), to_hash.size() );

uint64_t req_id = 0;
std::memcpy( &req_id, hash.data(), sizeof( req_id ) );
Expand Down
1 change: 0 additions & 1 deletion src/account/EscrowTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <utility>

#include "crypto/hasher/hasher_impl.hpp"
#include "base/blob.hpp"

namespace sgns
Expand Down
1 change: 0 additions & 1 deletion src/account/GeniusNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ namespace sgns
transaction_manager_ = TransactionManager::New( tx_globaldb_,
io_,
account_,
std::make_shared<crypto::HasherImpl>(),
blockchain_,
is_full_node_,
subnet_id_ );
Expand Down
1 change: 0 additions & 1 deletion src/account/GeniusNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "account/ChainRpcEndpointProvider.hpp"
#include "eth/eth_watch_service.hpp"
#include <ipfs_lite/ipfs/graphsync/graphsync.hpp>
#include "crypto/hasher/hasher_impl.hpp"
#include "processing/impl/processing_core_impl.hpp"
#include "processing/impl/processing_subtask_result_storage_impl.hpp"
#include "processing/processing_service.hpp"
Expand Down
8 changes: 3 additions & 5 deletions src/account/GeniusTransaction.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "GeniusTransaction.hpp"

#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"

namespace sgns
{
Expand Down Expand Up @@ -37,8 +37,7 @@ namespace sgns
dag_st.clear_signature();
dag_st.clear_data_hash();

auto hasher_ = std::make_shared<crypto::HasherImpl>();
auto hash = hasher_->blake2b_256( SerializeByteVector() );
auto hash = crypto::blake2b_256( SerializeByteVector() );

dag_st.set_data_hash( hash.toReadableString() );
dag_st.set_signature( std::move( signature ) );
Expand All @@ -52,8 +51,7 @@ namespace sgns
dag_copy.clear_signature();
dag_copy.clear_data_hash();

auto hasher_ = std::make_shared<crypto::HasherImpl>();
auto calculated_hash = hasher_->blake2b_256( SerializeByteVector( dag_copy ) );
auto calculated_hash = crypto::blake2b_256( SerializeByteVector( dag_copy ) );

return hash == calculated_hash.toReadableString();
}
Expand Down
2 changes: 0 additions & 2 deletions src/account/Migration3_6_0To3_7_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "account/proto/SGTransaction.pb.h"
#include "base/sgns_version.hpp"
#include "blockchain/Blockchain.hpp"
#include "crypto/hasher/hasher_impl.hpp"
#include "storage/database_error.hpp"

#include <algorithm>
Expand Down Expand Up @@ -288,7 +287,6 @@ namespace sgns
transaction_manager_ = TransactionManager::New( db_3_7_0_,
ioContext_,
account_,
std::make_shared<crypto::HasherImpl>(),
blockchain_,
is_full_node_ );
}
Expand Down
5 changes: 2 additions & 3 deletions src/account/MigrationTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <fmt/format.h>

#include "base/blob.hpp"
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"

namespace sgns
{
Expand Down Expand Up @@ -201,8 +201,7 @@ namespace sgns
const TokenID &token_id )
{
const auto payload = fmt::format( "migration:{}:{}:{}", from_version, source_address, token_id.ToHex() );
auto hasher = std::make_shared<crypto::HasherImpl>();
return hasher->blake2b_256( std::vector<uint8_t>( payload.begin(), payload.end() ) ).toReadableString();
return crypto::blake2b_256( std::vector<uint8_t>( payload.begin(), payload.end() ) ).toReadableString();
}

MigrationTransaction MigrationTransaction::New( uint64_t amount,
Expand Down
1 change: 0 additions & 1 deletion src/account/MintTransactionV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "account/MintTransactionV2.hpp"

#include "base/blob.hpp"
#include "crypto/hasher/hasher_impl.hpp"

namespace sgns
{
Expand Down
7 changes: 3 additions & 4 deletions src/account/ProcessingTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "account/ProcessingTransaction.hpp"

#include <utility>
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"

namespace sgns
{
Expand All @@ -22,10 +22,9 @@ namespace sgns
subtask_ids_( std::move( subtask_ids ) ),
node_addresses_( std::move( node_addresses ) )
{
auto hasher_ = std::make_shared<sgns::crypto::HasherImpl>();
auto hash_data = hasher_->blake2b_256( SerializeByteVector() );
auto hash_data = crypto::blake2b_256( SerializeByteVector() );
dag_st.set_data_hash( hash_data.toReadableString() );
hash_data = hasher_->blake2b_256( std::vector<uint8_t>{ job_id.begin(), job_id.end() } );
hash_data = crypto::blake2b_256( std::vector<uint8_t>{ job_id.begin(), job_id.end() } );
job_hash_ = uint256_t{ "0x" + hash_data.toReadableString() };
}

Expand Down
9 changes: 3 additions & 6 deletions src/account/TransactionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "account/proto/SGTransaction.pb.h"
#include "crdt/proto/delta.pb.h"
#include "base/sgns_version.hpp"
#include "crypto/hasher.hpp"

#include "outcome/outcome.hpp"
#include "proof/ProcessingProof.hpp"
Expand Down Expand Up @@ -107,7 +108,6 @@ namespace sgns
std::shared_ptr<TransactionManager> TransactionManager::New( std::shared_ptr<crdt::GlobalDB> processing_db,
std::shared_ptr<boost::asio::io_context> ctx,
std::shared_ptr<GeniusAccount> account,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<Blockchain> blockchain,
bool full_node,
uint16_t subnet_id,
Expand All @@ -117,7 +117,6 @@ namespace sgns
auto instance = std::shared_ptr<TransactionManager>( new TransactionManager( std::move( processing_db ),
std::move( ctx ),
std::move( account ),
std::move( hasher ),
std::move( blockchain ),
full_node,
subnet_id,
Expand Down Expand Up @@ -251,7 +250,6 @@ namespace sgns
TransactionManager::TransactionManager( std::shared_ptr<crdt::GlobalDB> processing_db,
std::shared_ptr<boost::asio::io_context> ctx,
std::shared_ptr<GeniusAccount> account,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<Blockchain> blockchain,
bool full_node,
uint16_t subnet_id,
Expand All @@ -260,7 +258,6 @@ namespace sgns
globaldb_m( std::move( processing_db ) ),
ctx_m( std::move( ctx ) ),
account_m( std::move( account ) ),
hasher_m( std::move( hasher ) ),
blockchain_( std::move( blockchain ) ),
full_node_m( full_node ),
subnet_id_( subnet_id ),
Expand Down Expand Up @@ -784,7 +781,7 @@ namespace sgns
{
return outcome::failure( boost::system::error_code{} );
}
auto hash_data = hasher_m->blake2b_256( std::vector<uint8_t>{ job_id.begin(), job_id.end() } );
auto hash_data = crypto::blake2b_256( std::vector<uint8_t>{ job_id.begin(), job_id.end() } );
const std::string lock_id = "0x" + hash_data.toReadableString();

BOOST_OUTCOME_TRY(
Expand Down Expand Up @@ -3874,7 +3871,7 @@ namespace sgns

const uint64_t registry_epoch = validator_registry->GetRegistryEpoch();
const auto registry_cid = validator_registry->GetRegistryCid();
auto registry_hash = hasher_m->sha2_256( registry_cid.data(), registry_cid.size() );
auto registry_hash = crypto::sha2_256( registry_cid.data(), registry_cid.size() );

if ( auto checkpoint_res = account_m->GetUTXOManager().CreateCheckpoint( registry_epoch,
tx_hash_bin.value(),
Expand Down
6 changes: 0 additions & 6 deletions src/account/TransactionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "account/PublicChainInputValidator.hpp"
#include "base/logger.hpp"
#include "base/buffer.hpp"
#include "crypto/hasher.hpp"

#include "blockchain/Blockchain.hpp"
#include "processing/proto/SGProcessing.pb.h"
Expand Down Expand Up @@ -85,7 +84,6 @@ namespace sgns
* @param[in] processing_db Database of the CRDT
* @param[in] ctx The io context used to run its inner methods
* @param[in] account Genius account to be used
* @param[in] hasher Hasher to be used
* @param[in] full_node Parameter to indicate if the account is a full node
* @param[in] timestamp_tolerance Time to analyze a transaction with the same nonce/key
* @param[in] mutability_window Window of time where a transaction can be modified
Expand All @@ -98,7 +96,6 @@ namespace sgns
std::shared_ptr<crdt::GlobalDB> processing_db,
std::shared_ptr<boost::asio::io_context> ctx,
std::shared_ptr<GeniusAccount> account,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<Blockchain> blockchain,
bool full_node = false,
uint16_t subnet_id = 0,
Expand Down Expand Up @@ -317,7 +314,6 @@ namespace sgns
TransactionManager( std::shared_ptr<crdt::GlobalDB> processing_db,
std::shared_ptr<boost::asio::io_context> ctx,
std::shared_ptr<GeniusAccount> account,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<Blockchain> blockchain,
bool full_node,
std::chrono::milliseconds timestamp_tolerance,
Expand All @@ -326,7 +322,6 @@ namespace sgns
TransactionManager( std::shared_ptr<crdt::GlobalDB> processing_db,
std::shared_ptr<boost::asio::io_context> ctx,
std::shared_ptr<GeniusAccount> account,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<Blockchain> blockchain,
bool full_node,
uint16_t subnet_id,
Expand Down Expand Up @@ -495,7 +490,6 @@ namespace sgns

std::shared_ptr<boost::asio::io_context> ctx_m;
std::shared_ptr<GeniusAccount> account_m;
std::shared_ptr<crypto::Hasher> hasher_m;
std::shared_ptr<Blockchain> blockchain_;
bool full_node_m;
uint16_t subnet_id_ = 0; ///< Subnet ID from config (reserved).
Expand Down
17 changes: 6 additions & 11 deletions src/blockchain/Consensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "base/hexutil.hpp"
#include "base/sgns_version.hpp"
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"
#include "account/GeniusAccount.hpp"
#include "blockchain/ConsensusAuth.hpp"

Expand Down Expand Up @@ -525,8 +525,7 @@ namespace sgns
return AggregatorRole::NotInRegistry;
}

sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( proposal.proposal_id().data(), proposal.proposal_id().size() );
auto hash = sgns::crypto::sha2_256( proposal.proposal_id().data(), proposal.proposal_id().size() );
uint64_t base_index = 0;
for ( size_t i = 0; i < sizeof( uint64_t ) && i < hash.size(); ++i )
{
Expand Down Expand Up @@ -2585,8 +2584,7 @@ namespace sgns
return outcome::failure( std::errc::invalid_argument );
}

sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( serialized.data(), serialized.size() );
auto hash = sgns::crypto::sha2_256( serialized.data(), serialized.size() );
ConsensusManagerLogger()->debug( "{}: success", __func__ );
return base::hex_lower( gsl::span<const uint8_t>( hash.data(), hash.size() ) );
}
Expand All @@ -2601,8 +2599,7 @@ namespace sgns
{
return outcome::failure( std::errc::invalid_argument );
}
sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( payload.data(), payload.size() );
auto hash = sgns::crypto::sha2_256( payload.data(), payload.size() );
return std::string( reinterpret_cast<const char *>( hash.data() ), hash.size() );
}

Expand Down Expand Up @@ -2652,8 +2649,7 @@ namespace sgns
return outcome::failure( std::errc::invalid_argument );
}

sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( subject_type.data(), subject_type.size() );
auto hash = sgns::crypto::sha2_256( subject_type.data(), subject_type.size() );
return std::string( reinterpret_cast<const char *>( hash.data() ), hash.size() );
}

Expand Down Expand Up @@ -2852,8 +2848,7 @@ namespace sgns
return {};
}

sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( signing_bytes.value().data(), signing_bytes.value().size() );
auto hash = sgns::crypto::sha2_256( signing_bytes.value().data(), signing_bytes.value().size() );
auto proposal_id = base::hex_lower( gsl::span<const uint8_t>( hash.data(), hash.size() ) );
ConsensusManagerLogger()->debug( "{}: Proposal ID {} created", __func__, proposal_id.substr( 0, 8 ) );
return proposal_id;
Expand Down
5 changes: 2 additions & 3 deletions src/blockchain/ConsensusAuth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "account/GeniusAccount.hpp"
#include "base/hexutil.hpp"
#include "blockchain/impl/proto/Consensus.pb.h"
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"
#include <gsl/span>
#include "outcome/outcome.hpp"

Expand Down Expand Up @@ -105,8 +105,7 @@ namespace sgns
return outcome::failure( signing_bytes.error() );
}

sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( signing_bytes.value().data(), signing_bytes.value().size() );
auto hash = sgns::crypto::sha2_256( signing_bytes.value().data(), signing_bytes.value().size() );
return base::hex_lower( gsl::span<const uint8_t>( hash.data(), hash.size() ) );
}

Expand Down
5 changes: 2 additions & 3 deletions src/blockchain/ValidatorRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "blockchain/Consensus.hpp"
#include "blockchain/ConsensusAuth.hpp"
#include "blockchain/impl/proto/ValidatorRegistry.pb.h"
#include "crypto/hasher/hasher_impl.hpp"
#include "crypto/hasher.hpp"
#include "crdt/graphsync_dagsyncer.hpp"

namespace sgns
Expand Down Expand Up @@ -705,8 +705,7 @@ namespace sgns
payload.push_back( '\n' );
payload += subject_hashes[i];
}
sgns::crypto::HasherImpl hasher;
auto hash = hasher.sha2_256( payload.data(), payload.size() );
auto hash = sgns::crypto::sha2_256( payload.data(), payload.size() );
return base::hex_lower( gsl::span<const uint8_t>( hash.data(), hash.size() ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(hasher
hasher/hasher_impl.cpp
hasher.cpp
)
target_link_libraries(hasher
PRIVATE
Expand Down
Loading
Loading