1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
pub mod circuit;
mod posw;
use posw::{HG, M};
pub mod error;
use snarkvm_algorithms::snark;
use snarkvm_curves::{bls12_377::Bls12_377, traits::PairingEngine};
use snarkvm_dpc::block::{
merkle_root_with_subroots,
pedersen_merkle_root,
MerkleRootHash,
PedersenMerkleRootHash,
MASKED_TREE_DEPTH,
};
#[deprecated]
pub type GM17<E> = snark::gm17::GM17<E, PoswCircuit<<E as PairingEngine>::Fr>, Vec<<E as PairingEngine>::Fr>>;
pub type PoswMarlin = Posw<Marlin<Bls12_377>, Bls12_377>;
pub type Marlin<E> =
snarkvm_marlin::snark::MarlinSystem<E, PoswCircuit<<E as PairingEngine>::Fr>, Vec<<E as PairingEngine>::Fr>>;
pub type Posw<S, E> = posw::Posw<S, <E as PairingEngine>::Fr, M, HG, params::PoSWParams>;
type PoswCircuit<F> = circuit::POSWCircuit<F, M, HG, params::PoSWParams>;
mod params {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PoSWParams;
impl crate::circuit::POSWCircuitParameters for PoSWParams {
const MASK_LENGTH: usize = 32;
}
}
pub fn txids_to_roots(transaction_ids: &[[u8; 32]]) -> (MerkleRootHash, PedersenMerkleRootHash, Vec<[u8; 32]>) {
let (root, subroots) = merkle_root_with_subroots(transaction_ids, MASKED_TREE_DEPTH);
let mut merkle_root_bytes = [0u8; 32];
merkle_root_bytes[..].copy_from_slice(&root);
(
MerkleRootHash(merkle_root_bytes),
pedersen_merkle_root(&subroots),
subroots,
)
}
#[cfg(test)]
mod tests {
use super::*;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use snarkvm_algorithms::traits::SNARK;
use snarkvm_utilities::bytes::FromBytes;
#[test]
fn test_load_verify_only() {
let _params = PoswMarlin::verify_only().unwrap();
}
#[test]
fn test_load() {
let _params = PoswMarlin::load().unwrap();
}
#[test]
#[allow(deprecated)]
fn test_posw_gm17() {
let rng = &mut XorShiftRng::seed_from_u64(1234567);
pub type PoswGM17 = Posw<GM17<Bls12_377>, Bls12_377>;
let posw = PoswGM17::setup(rng).unwrap();
let difficulty_target = 0xFFFF_FFFF_FFFF_FFFF_u64;
let transaction_ids = vec![[1u8; 32]; 8];
let (_, pedersen_merkle_root, subroots) = txids_to_roots(&transaction_ids);
let (nonce, proof) = posw
.mine(&subroots, difficulty_target, &mut rand::thread_rng(), std::u32::MAX)
.unwrap();
assert_eq!(proof.len(), 193);
let proof = <GM17<Bls12_377> as SNARK>::Proof::read(&proof[..]).unwrap();
posw.verify(nonce, &proof, &pedersen_merkle_root).unwrap();
}
#[test]
fn test_posw_marlin() {
let rng = &mut XorShiftRng::seed_from_u64(1234567);
let universal_srs = snarkvm_marlin::MarlinTestnet1::universal_setup(10000, 10000, 100000, rng).unwrap();
let posw = PoswMarlin::index(universal_srs).unwrap();
let difficulty_target = 0xFFFF_FFFF_FFFF_FFFF_u64;
let transaction_ids = vec![[1u8; 32]; 8];
let (_, pedersen_merkle_root, subroots) = txids_to_roots(&transaction_ids);
let (nonce, proof) = posw
.mine(&subroots, difficulty_target, &mut rand::thread_rng(), std::u32::MAX)
.unwrap();
assert_eq!(proof.len(), 972);
let proof = <Marlin<Bls12_377> as SNARK>::Proof::read(&proof[..]).unwrap();
posw.verify(nonce, &proof, &pedersen_merkle_root).unwrap();
}
}