You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pallets/faucet/src/faucet.rs
+33-38Lines changed: 33 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,36 @@
1
-
//! Implementation of the faucet functionality
1
+
//! # proof-of-work
2
2
//!
3
-
//! This module contains the core logic for the faucet pallet, including:
4
-
//! - The execution function that handles faucet requests
5
-
//! - Hash calculation and verification functions for proof-of-work
6
-
//! - Block hash retrieval and validation functions
3
+
//! The following steps are required to generate a valid proof-of-work:
4
+
//! - Concatenate the current block hash with the receiver key bytes and hash the result using keccak256. (reference [hash_block_and_key])
5
+
//! - Concatenate a random nonce with the result of the previous step, hash it with sha256 and again with keccak256. (reference [create_seal_hash])
6
+
//! - Transform the result hash to a u128 number and multiply it by 1_000_000. (reference [hash_meets_difficulty])
7
+
//! - If the multiplication result exceeds the maximum possible u128 value, the hash is invalid. Try again with a new random nonce and updated block hash.
8
+
//! - If it doesn't, the proof-of-work is valid and the result may be submitted.
9
+
//!
10
+
//! ## Pseudocode
11
+
//! ```x
12
+
//! u128 difficulty = 1_000_000;
13
+
//! while true {
14
+
//! u64 nonce = random_u64();
15
+
//! u8[] block_hash = current_block_hash;
16
+
//!
17
+
//! // This should result in a byte array with size 64 (trim the end of key bytes if necessary)
0 commit comments