Skip to content

Commit

Permalink
Shosha compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaker committed Nov 27, 2023
1 parent c5bfb66 commit c78d25d
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 152 deletions.
131 changes: 69 additions & 62 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ ark-crypto-primitives = {version="0.4.0", optional=true}
curve25519-dalek = {version="4.0.0", optional=true}
group = {version="0.13.0", optional=true}

# anemoi = {git="https://github.com/mmaker/anemoi"}

[features]
default = []
arkworks = ["dep:ark-ff", "dep:ark-ec", "dep:ark-serialize", "dep:ark-crypto-primitives"]
dalek = ["dep:curve25519-dalek"]
zkcrypto = ["dep:group"]

[dev-dependencies]
ark-bls12-381 = "0.4.0"
ark-std = "0.4.0"
sha2 = "0.10.7"
blake2 = "0.10.6"
Expand Down
4 changes: 3 additions & 1 deletion examples/bulletproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ fn main() {

// the test vectors
let a = (0..size).map(|x| F::from(x as u32)).collect::<Vec<_>>();
let b = (0..size).map(|x| F::from(x as u32 + 42)).collect::<Vec<_>>();
let b = (0..size)
.map(|x| F::from(x as u32 + 42))
.collect::<Vec<_>>();
let ab = inner_prod(&a, &b);
// the generators to be used for respectively a, b, ip
let g = (0..a.len())
Expand Down
18 changes: 7 additions & 11 deletions scripts/useful_bits_modp.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
"""
Use this program to find the number of bits that appear uniformly random
in the uniform distribution mod p.
While this function is trivial for byte-oriented hashes, for algebraic hashes, it requires proper implementation.
Many implementations simply truncate the least-significant bits, but this approach
results in a statistical deviation from uniform randomness. The number of useful bits, denoted as `n`,
has a statistical distance from uniformly random given by:
p is provided on stdin in any format that python can eval. For example,
$ python3 scripts/useful_bits_modp.py <<< 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
"""


def useful_bits(p):
for n in range(p.bit_length()-1, 0, -1):
alpha = p % 2^n
if n+1 + p.bit_length() - alpha.bit_length() - (2^n-alpha).bit_length() >= 128:
return n
return max(
n for n in range(p.bit_length() - 1, 0, -1)
if n + 1 + p.bit_length() - (alpha := p % 2 ** n).bit_length() -
(2 ** n - alpha).bit_length() >= 128
)


if __name__ == '__main__':
print(useful_bits(eval(input())))
print(useful_bits(eval(input())))
Loading

0 comments on commit c78d25d

Please sign in to comment.