Skip to content

Commit

Permalink
Merge branch 'implement-circuit'
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jan 23, 2020
2 parents da4eb66 + e7d538a commit 615ec19
Show file tree
Hide file tree
Showing 12 changed files with 897 additions and 74 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ bellperson = "0.4.1"
bincode = { version = "1.2", optional = true }
paired = "0.16.0"
ff = "=0.5.0"
blake2s_simd = "0.5"
byteorder = "1"
rand_xorshift = "0.2.0"

[dev-dependencies]
criterion = "0.3"
Expand Down
8 changes: 4 additions & 4 deletions benches/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn bench_hash(c: &mut Criterion) {
.map(|(i, _)| scalar_from_u64(i as u64))
.collect();

let mut group = c.benchmark_group("hash");
let mut group = c.benchmark_group(format!("hash-{}", ARITY * 32));

group.bench_with_input(
BenchmarkId::new("Sha2 256", "Generated scalars"),
Expand All @@ -22,7 +22,7 @@ fn bench_hash(c: &mut Criterion) {
let mut h = Sha256::new();

std::iter::repeat(())
.take(WIDTH)
.take(ARITY)
.map(|_| s.choose(&mut OsRng).unwrap())
.for_each(|scalar| {
for val in scalar.into_repr().as_ref() {
Expand All @@ -43,7 +43,7 @@ fn bench_hash(c: &mut Criterion) {
let mut h = Sha512::new();

std::iter::repeat(())
.take(WIDTH)
.take(ARITY)
.map(|_| s.choose(&mut OsRng).unwrap())
.for_each(|scalar| {
for val in scalar.into_repr().as_ref() {
Expand All @@ -64,7 +64,7 @@ fn bench_hash(c: &mut Criterion) {
let mut h = Poseidon::default();

std::iter::repeat(())
.take(WIDTH)
.take(ARITY)
.map(|_| s.choose(&mut OsRng).unwrap())
.for_each(|scalar| {
h.input(*scalar).unwrap();
Expand Down
10 changes: 7 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ fn main() {

let width = env::var("POSEIDON_WIDTH")
.map(|s| s.parse().expect("Failed to parse POSEIDON_WIDTH"))
.unwrap_or(2);
.unwrap_or(3);

let arity = width - 1;

let full_rounds = env::var("POSEIDON_FULL_ROUNDS")
.map(|s| s.parse().expect("Failed to parse POSEIDON_FULL_ROUNDS"))
Expand All @@ -23,13 +25,15 @@ fn main() {
write!(
&mut f,
r#"// Poseidon constants
/// Width of a Poseidon hash, in elemen
/// Width of a Poseidon permutation, in elements
pub const WIDTH: usize = {};
/// Arity of a Poseidon hash, in elements
pub const ARITY: usize = {};
pub(crate) const FULL_ROUNDS: usize = {};
pub(crate) const PARTIAL_ROUNDS: usize = {};
"#,
width, full_rounds, partial_rounds
width, arity, full_rounds, partial_rounds
)
.expect("Could not write file");
}
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions parameters/round_numbers-768-3-128-1-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
N: 768
Security level M: 128
Field: Prime
S-box: f(x) = x^5
[8, 55, 79, 20224]
Recommendation for N=768, t=3:
R_F = 8
R_P = 55
S-box cost = 79
Size cost = 20224
--- Round numbers (with security margin) ---
Format: [Security Level, Field Size, # Elements, Field, S-Box, R_F, R_P]
['45', '45', '3', 'GF(2^n)', 'x^3', '8', '28']
['45', '45', '3', 'GF(p)', 'x^3', '8', '26']
['45', '90', '3', 'GF(2^n)', 'x^3', '8', '28']
['45', '90', '3', 'GF(p)', 'x^3', '8', '26']
['80', '80', '4', 'GF(2^n)', 'x^3', '8', '53']
['80', '80', '4', 'GF(p)', 'x^3', '8', '51']
['80', '160', '3', 'GF(2^n)', 'x^3', '8', '52']
['80', '160', '3', 'GF(p)', 'x^3', '8', '50']
['80', '160', '11', 'GF(2^n)', 'x^3', '8', '54']
['80', '160', '11', 'GF(p)', 'x^3', '8', '52']
['128', '128', '4', 'GF(2^n)', 'x^3', '8', '85']
['128', '128', '4', 'GF(p)', 'x^3', '8', '83']
['128', '256', '3', 'GF(2^n)', 'x^3', '8', '85']
['128', '256', '3', 'GF(p)', 'x^3', '8', '83']
['128', '128', '12', 'GF(2^n)', 'x^3', '8', '88']
['128', '128', '12', 'GF(p)', 'x^3', '8', '85']
['128', '256', '11', 'GF(2^n)', 'x^3', '8', '88']
['128', '256', '11', 'GF(p)', 'x^3', '8', '85']
['256', '128', '8', 'GF(2^n)', 'x^3', '8', '86']
['256', '128', '8', 'GF(p)', 'x^3', '8', '84']
['256', '512', '3', 'GF(2^n)', 'x^3', '8', '171']
['256', '512', '3', 'GF(p)', 'x^3', '8', '169']
['256', '128', '14', 'GF(2^n)', 'x^3', '8', '88']
['256', '128', '14', 'GF(p)', 'x^3', '8', '85']
['256', '512', '11', 'GF(2^n)', 'x^3', '8', '174']
['256', '512', '11', 'GF(p)', 'x^3', '8', '171']
Loading

0 comments on commit 615ec19

Please sign in to comment.