Skip to content

Commit d543888

Browse files
committed
Proof of work in config
1 parent b13e2e4 commit d543888

6 files changed

Lines changed: 258 additions & 139 deletions

File tree

src/bits.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
use std::hash::Hash;
1+
use std::{
2+
cmp::Ordering,
3+
fmt::{self, Display},
4+
hash::Hash,
5+
};
26

3-
use serde::Serialize;
7+
use serde::{Deserialize, Serialize};
48

59
/// Wrapper for `bits` value types.
6-
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
10+
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
711
pub struct Bits(f64);
812

913
impl Hash for Bits {
@@ -36,3 +40,21 @@ impl From<Bits> for f64 {
3640
bits.0
3741
}
3842
}
43+
44+
impl Display for Bits {
45+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
<f64 as Display>::fmt(&self.0, f)
47+
}
48+
}
49+
50+
impl PartialOrd for Bits {
51+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
52+
self.0.partial_cmp(&other.0)
53+
}
54+
}
55+
56+
impl Ord for Bits {
57+
fn cmp(&self, other: &Self) -> Ordering {
58+
self.0.partial_cmp(&other.0).unwrap()
59+
}
60+
}

src/crypto/proof_of_work/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod none_engine;
55
use std::sync::{Arc, LazyLock};
66

77
use ark_std::rand::{CryptoRng, RngCore};
8-
use serde::Serialize;
8+
use serde::{Deserialize, Serialize};
99
use spongefish::{
1010
Codec, Decoding, DuplexSpongeInterface, ProverState, VerificationError, VerificationResult,
1111
VerifierState,
@@ -47,9 +47,11 @@ pub trait Engine: Protocol {
4747

4848
assert_obj_safe!(Engine);
4949

50-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
50+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
5151
pub struct Config {
5252
pub engine_id: ProtocolId,
53+
54+
// TODO: Use threshold to be more determistic.
5355
pub difficulty: Bits,
5456
}
5557

@@ -77,13 +79,6 @@ impl Config {
7779
}
7880
}
7981

80-
pub fn sha2(difficulty: Bits) -> Self {
81-
Self {
82-
engine_id: Sha2::new().protocol_id(),
83-
difficulty,
84-
}
85-
}
86-
8782
#[cfg_attr(feature = "tracing", instrument(skip(prover_state)))]
8883
pub fn prove<H, R>(&self, prover_state: &mut ProverState<H, R>)
8984
where

src/transcript/protocol_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
44
use std::fmt::{Debug, Display};
55

6-
use serde::Serialize;
6+
use serde::{Deserialize, Serialize};
77

8-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]
8+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
99
pub struct ProtocolId([u8; 32]);
1010

1111
pub trait Protocol {

0 commit comments

Comments
 (0)