fud, dht: add a PoW to fud for node ID generation

- The node ID is not stored on the disk anymore, it's generated when fud starts.

- PoW uses Equi-X (https://spec.torproject.org/hspow-spec/v1-equix.html), the challenge contains a recent BTC block hash because it's 1) unpredictable 2) known by all fud nodes 3) periodically updated 4) stable. Once the block you chose for your node ID is too old, you will generate another one with another keypair and block hash (or other nodes will exclude you from their DHT).

- BTC block hashes are fetched from the Electrum nodes defined in the config file (you can use tor/i2p nodes if you want).

- Equi-X challenge is `(public_key || btc_block_hash || nonce)`, a node ID is `Hash(equix_challenge || equix_solution)`. You must evaluate the PoW to get a valid node ID.

- The keypair is random and regenerated when you create a new node ID, it's only there so that you can sign messages.

- `Dht` and `DhtHandler` now have a generic parameter which is any struct implementing the `DhtNode` trait. It was not needed before because fud did not use any fud-specific fields for its node struct. All the PoW stuff is in `fud` and NOT in `dht`.

- `fud/src/equix.rs` does not depend on fud, we can move it elsewhere if we want to use Equi-X in another bin.

- `FudPingRequest` now includes a random u64, the other node must provide a signature of that u64 (along with other data, including the data making up its node ID) in its `FudPingReply`.
This commit is contained in:
epiphany
2025-08-21 23:05:06 +02:00
parent 1052333fd4
commit d34113e8a5
14 changed files with 1243 additions and 321 deletions

47
Cargo.lock generated
View File

@@ -783,6 +783,15 @@ dependencies = [
"wyz",
]
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "blake2b_simd"
version = "1.0.3"
@@ -2680,6 +2689,19 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "equix"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89178c5241f5cc0c8f2b5ac5008f3c7a32caad341b1ec747a6e1e51d2e877110"
dependencies = [
"arrayvec",
"hashx",
"num-traits",
"thiserror 2.0.12",
"visibility",
]
[[package]]
name = "errno"
version = "0.3.13"
@@ -2823,6 +2845,12 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "fixed-capacity-vec"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b31a14f5ee08ed1a40e1252b35af18bed062e3f39b69aab34decde36bc43e40"
[[package]]
name = "fixed-hash"
version = "0.8.0"
@@ -3036,16 +3064,20 @@ name = "fud"
version = "0.5.0"
dependencies = [
"async-trait",
"blake2",
"blake3",
"bs58",
"darkfi",
"darkfi-sdk",
"darkfi-serial",
"easy-parallel",
"equix",
"futures",
"log",
"num-bigint",
"rand 0.8.5",
"serde",
"sha2",
"signal-hook",
"signal-hook-async-std",
"simplelog",
@@ -3437,6 +3469,21 @@ dependencies = [
"hashbrown 0.15.4",
]
[[package]]
name = "hashx"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cb639748a589a17df2126f8015897ab416e81113afb82f56df5d47fa1486ab1"
dependencies = [
"arrayvec",
"blake2",
"dynasmrt",
"fixed-capacity-vec",
"hex",
"rand_core 0.9.3",
"thiserror 2.0.12",
]
[[package]]
name = "heck"
version = "0.3.3"