This project is dedicated to the world community as an Open-source Post-quantum SPHINX blockchain, means anyone can join and contribute based on his/ her passion and skills. SPHINX is a blockchain protocol designed to provide secure and scalable solutions in the post-quantum era. The project aims to develop a robust and decentralized network using a Proof of Work (PoW) consensus algorithm initiated by the community. We thrilled to introduce a new design for Proof-of-Work operation.
The SPHINXHash
hash function used in the code is based on SWIFFTX which is a cryptographic hash function, the designed to provide secure hashing capabilities because its relly on Lattice-based
that today we are knowing its promising secure in the post-quantum era. This hash function takes a message as input and produces a fixed-size output of 256 bits.
The calculateHash
function in the SPHINXMiningAlgorithm
namespace is used to calculate the hash of a given message with a specified number of required leading zeros. It iterates through nonce values until it finds a hash that meets the difficulty target. The function appends the nonce to the message, calculates the hash using the SPHINX_256
hash function, and checks if the hash meets the required number of leading zeros.
The meetsDifficultyTarget
function is a custom function used to check if a given hash meets the difficulty target. It takes the hash and the required number of leading zeros as input and iterates through the hash characters to check if the hash has the required number of leading zeros. It returns false
if any character is not '0', indicating that the hash does not meet the difficulty target.
The solveNonce
function in the SPHINXPoW
namespace is responsible for solving the nonce value for a given data and difficulty level. It iterates through nonce values and combines them with the data to mine a block using the mineBlock
function from the Miner
class. It then checks if the mined block's hash meets the difficulty target by calling the meetsDifficultyTarget
function.
The adjustDifficulty
function is used to dynamically adjust the difficulty level based on the network hash rate and other factors. It calculates the expected number of blocks per day, adjusts the target blocks per day for developer mining, and calculates the network target hash rate. It then adjusts the difficulty target by reducing or increasing the target based on the network hash rate and a predefined adjustment factor.
The SPHINXPoW algorithm includes several mathematical operations for nonce calculation and difficulty adjustment. This will help the algorithm safe from brute-force attacked by set up the randomness. Here are some of the mathematical properties used in the code:
-
multiply
Function: This inline function is used to multiply the upper and lower digits of a number. It takes a numberk
as input, splits it into upper and lower digits, and multiplies them. If either the upper or lower digits are zero, the function returnsk
as it is. -
extract_32_digits
Function: This inline function extracts 32 digits from a givennumberk
. It uses mathematical operations likefrexp
,modf
, and casting to extract the desired digits. -
select_and_do_operation
Function: This inline function selects and performs mathematical operations based on a sequence number (seq
) and a given numberk
. It supports operations like division, multiplication, addition, square root, exponential, trigonometric functions, logarithmic functions, and others. The function checks the sequence number and performs the corresponding operation onk
. If the sequence number does not match any operation, it returns a default value of 1.
The isValidHash
function is used to check if a given hash has the required number of leading zeros. It iterates through the hash characters and checks if the number of leading zeros matches the required number. It returns true
if the hash is valid, indicating that it meets the required leading zeros.
To minimizing energy consumption associated with Proof-of-Work (PoW) systems, we have implemented a unique approach called the "Developer Mining Phase." This phase aims to significantly reduce energy usage while providing a rewarding opportunity for developers, founders, and contributors.
During the Developer Mining Phase, we introduce specific scenarios that allow developers to mine with reduced energy consumption. By allocating a portion of the total mining assets to developers, we ensure their valuable contributions are duly recognized and rewardeds.
The "Developer Mining Phase" not only reduces energy consumption in PoW systems but also provides a platform to appreciate the exceptional work done by developers, founders, and contributors. By incentivizing their efforts and introducing energy-efficient mining strategies, we create a sustainable and rewarding environment for all participants.
The condition for the developer mining phase is based on the developerMining
variable, which is initially set to false
. In the code, there are several scenarios mentioned that can trigger the developer mining phase. These scenarios are as follows:
a. Scenario 1: Developer mining a percentage of total assets with reduced difficulty - When developerMining
is true
, the mining assets for developers are calculated, and the difficulty is adjusted accordingly.
b. Scenario 2: Probability-based developer mining over a certain period - If the random number generated (dis(gen) < miningProbability
) satisfies the probability condition, the developerMining
variable is set to true
, and the difficulty is adjusted accordingly.
While in the developer mining phase, the mining process continues within the performMining()
function. The mining process involves performing mathematical operations on a variable k
, adjusting the difficulty, and checking if the target hash is met.
If a successful mining result is obtained, the code performs the following actions:
a. Scenario 3: Automatically switching to the normal mining phase once developer mining is done - If developerMining
is true
and the developerMiningAssets
is depleted (developerMiningAssets <= 0
), the developerMining
variable is set to false
, and the difficulty is adjusted accordingly.
b. Outputting the successful mining result - The successful mining result is displayed on the console.
Conditions for Exiting the Mining Process:
The mining process continues in a loop until certain conditions are met:
a. If the target hash is met (if (meetsDifficultyTarget(std::to_string(k), target))
), the loop is exited, and the successful mining result is outputted.
b. If a timeout duration is reached (if (currentTime - startTime >= timeoutDuration)
), the mining process is terminated, and a timeout message is displayed.
In summary, the "developers mining phase" condition is based on the developerMining
variable, which is triggered by certain scenarios and probability-based conditions. During the developer mining phase, the mining process continues with adjusted difficulty. Once the mining goals or conditions are met, the code can automatically switch to the normal mining phase or terminate the mining process based on the timeout duration.
This repository is part of the SPHINXMiner
Please note that the code in this repository is a part of the SPHINXPoW algorithm, which is currently in development and not fully integrated or extensively tested for functionality. The purpose of this repository is to provide a framework and algorithm for the mining scheme in the SPHINX blockchain project.
As the project progresses, further updates and enhancements will be made to ensure the code's stability and reliability. We encourage contributors to participate in improving and refining the SPHINXPoW algorithm by submitting pull requests and providing valuable insights.
We appreciate your understanding and look forward to collaborative efforts in shaping the future of the SPHINX blockchain project.
To get started with the SPHINX blockchain project, follow the instructions below:
- Clone the repository:
git clone https://github.com/ChyKusuma/SPHINXPoW.git
- Install the necessary dependencies (List the dependencies or provide a link to the installation guide).
- Explore the codebase to understand the project structure and components.
- Run the project or make modifications as needed.
We welcome contributions from the developer community to enhance the SPHINX blockchain project. If you are interested in contributing, please follow the guidelines below:
- Fork the repository on GitHub.
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
orgit checkout -b bugfix/your-bug-fix
. - Make your modifications and ensure the code remains clean and readable.
- Write tests to cover the changes you've made, if applicable.
- Commit your changes:
git commit -m "Description of your changes"
. - Push the branch to your forked repository:
git push origin your-branch-name
. - Open a pull request against the main repository, describing your changes and the problem it solves.
- Insert your information (i.e name, email) in the authors space.
Specify the license under which the project is distributed (MIT License).
If you have any questions, suggestions, or feedback regarding the SPHINX blockchain project, feel free to reach out to us at [email protected].