mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
simplify by avoiding unnecessary conversions (#3343)
This commit is contained in:
parent
992d450e0a
commit
e28e02ecd4
4 changed files with 22 additions and 30 deletions
|
@ -76,6 +76,7 @@ where
|
|||
let mut uvs = vec![0u64; 2 * proof.proof_size()];
|
||||
let mut xor0: u64 = 0;
|
||||
let mut xor1: u64 = 0;
|
||||
let node_mask: u64 = to_u64!(self.params.edge_mask);
|
||||
|
||||
for n in 0..proof.proof_size() {
|
||||
if nonces[n] > to_u64!(self.params.edge_mask) {
|
||||
|
@ -85,13 +86,10 @@ where
|
|||
return Err(ErrorKind::Verification("edges not ascending".to_owned()).into());
|
||||
}
|
||||
// 21 is standard siphash rotation constant
|
||||
let edge = to_edge!(
|
||||
T,
|
||||
siphash_block(&self.params.siphash_keys, nonces[n], 21, false)
|
||||
);
|
||||
uvs[2 * n] = to_u64!(edge & self.params.edge_mask);
|
||||
uvs[2 * n + 1] = to_u64!((edge >> 32) & self.params.edge_mask);
|
||||
let edge: u64 = siphash_block(&self.params.siphash_keys, nonces[n], 21, false);
|
||||
uvs[2 * n] = edge & node_mask;
|
||||
xor0 ^= uvs[2 * n];
|
||||
uvs[2 * n + 1] = (edge >> 32) & node_mask;
|
||||
xor1 ^= uvs[2 * n + 1];
|
||||
}
|
||||
if xor0 | xor1 != 0 {
|
||||
|
|
|
@ -76,7 +76,7 @@ where
|
|||
let mut ndir = vec![0usize; 2];
|
||||
let mut xor0: u64 = 0;
|
||||
let mut xor1: u64 = 0;
|
||||
let nodemask = self.params.edge_mask >> 1;
|
||||
let node_mask: u64 = to_u64!(self.params.edge_mask) >> 1;
|
||||
|
||||
for n in 0..proof.proof_size() {
|
||||
let dir = (nonces[n] & 1) as usize;
|
||||
|
@ -89,14 +89,12 @@ where
|
|||
if n > 0 && nonces[n] <= nonces[n - 1] {
|
||||
return Err(ErrorKind::Verification("edges not ascending".to_owned()).into());
|
||||
}
|
||||
let edge = to_edge!(
|
||||
T,
|
||||
siphash_block(&self.params.siphash_keys, nonces[n], 25, false)
|
||||
);
|
||||
// cuckarood uses a non-standard siphash rotation constant 25 as anti-ASIC tweak
|
||||
let edge: u64 = siphash_block(&self.params.siphash_keys, nonces[n], 25, false);
|
||||
let idx = 4 * ndir[dir] + 2 * dir;
|
||||
uvs[idx] = to_u64!(edge & nodemask);
|
||||
uvs[idx + 1] = to_u64!((edge >> 32) & nodemask);
|
||||
uvs[idx] = edge & node_mask;
|
||||
xor0 ^= uvs[idx];
|
||||
uvs[idx + 1] = (edge >> 32) & node_mask;
|
||||
xor1 ^= uvs[idx + 1];
|
||||
ndir[dir] += 1;
|
||||
}
|
||||
|
|
|
@ -72,11 +72,11 @@ where
|
|||
return Err(ErrorKind::Verification("wrong cycle length".to_owned()).into());
|
||||
}
|
||||
let nonces = &proof.nonces;
|
||||
let mut from = vec![0u32; proofsize];
|
||||
let mut to = vec![0u32; proofsize];
|
||||
let mut xor_from: u32 = 0;
|
||||
let mut xor_to: u32 = 0;
|
||||
let nodemask = self.params.edge_mask >> 1;
|
||||
let mut from = vec![0u64; proofsize];
|
||||
let mut to = vec![0u64; proofsize];
|
||||
let mut xor_from: u64 = 0;
|
||||
let mut xor_to: u64 = 0;
|
||||
let node_mask: u64 = to_u64!(self.params.edge_mask) >> 1;
|
||||
|
||||
for n in 0..proofsize {
|
||||
if nonces[n] > to_u64!(self.params.edge_mask) {
|
||||
|
@ -85,13 +85,11 @@ where
|
|||
if n > 0 && nonces[n] <= nonces[n - 1] {
|
||||
return Err(ErrorKind::Verification("edges not ascending".to_owned()).into());
|
||||
}
|
||||
let edge = to_edge!(
|
||||
T,
|
||||
siphash_block(&self.params.siphash_keys, nonces[n], 21, true)
|
||||
);
|
||||
from[n] = to_u32!(edge & nodemask);
|
||||
// 21 is standard siphash rotation constant
|
||||
let edge: u64 = siphash_block(&self.params.siphash_keys, nonces[n], 21, true);
|
||||
from[n] = edge & node_mask;
|
||||
xor_from ^= from[n];
|
||||
to[n] = to_u32!((edge >> 32) & nodemask);
|
||||
to[n] = (edge >> 32) & node_mask;
|
||||
xor_to ^= to[n];
|
||||
}
|
||||
if xor_from != xor_to {
|
||||
|
|
|
@ -74,6 +74,7 @@ where
|
|||
let nonces = &proof.nonces;
|
||||
let mut uvs = vec![0u64; 2 * proof.proof_size()];
|
||||
let mut xoruv: u64 = 0;
|
||||
let node_mask: u64 = to_u64!(self.params.edge_mask) << 1 | 1;
|
||||
|
||||
for n in 0..proof.proof_size() {
|
||||
if nonces[n] > to_u64!(self.params.edge_mask) {
|
||||
|
@ -83,12 +84,9 @@ where
|
|||
return Err(ErrorKind::Verification("edges not ascending".to_owned()).into());
|
||||
}
|
||||
// 21 is standard siphash rotation constant
|
||||
let edge = to_edge!(
|
||||
T,
|
||||
siphash_block(&self.params.siphash_keys, nonces[n], 21, true)
|
||||
);
|
||||
uvs[2 * n] = to_u64!(edge & self.params.edge_mask);
|
||||
uvs[2 * n + 1] = to_u64!((edge >> 32) & self.params.edge_mask);
|
||||
let edge: u64 = siphash_block(&self.params.siphash_keys, nonces[n], 21, true);
|
||||
uvs[2 * n] = edge & node_mask;
|
||||
uvs[2 * n + 1] = (edge >> 32) & node_mask;
|
||||
xoruv ^= uvs[2 * n] ^ uvs[2 * n + 1];
|
||||
}
|
||||
if xoruv != 0 {
|
||||
|
|
Loading…
Reference in a new issue