-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is very naive. It assumes that any top-level array should be represented as a RAM, and that all internal structure should be unfolded.
- Loading branch information
1 parent
4c5dafe
commit 805a7f4
Showing
22 changed files
with
467 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const u32 LEN = 2 | ||
const u32 LEN2 = 100 | ||
const u32 ACCESSES = 37 | ||
const u32 P_ = 8 | ||
|
||
struct Pt { | ||
field[P_] x | ||
field[P_] x2 | ||
} | ||
const Pt [LEN][LEN2] array = [[Pt {x: [0; P_], x2: [0; P_]}; LEN2], ...[[Pt {x: [100; P_], x2: [100; P_]}; LEN2] ; LEN-1]] // 638887 when LEN = 8190 // 63949 when LEN = 819 | ||
|
||
def main(private field[ACCESSES][2] idx) -> field: | ||
field sum = 0 | ||
for u32 i in 0..ACCESSES do | ||
field[2] access = idx[i] | ||
sum = sum + array[access[1]][access[0]].x[0] | ||
endfor | ||
return sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const u32 LEN = 6 | ||
const u32 ACCESSES = 3 | ||
|
||
struct Pt { | ||
field x | ||
field y | ||
field z | ||
} | ||
const Pt [LEN] array = [Pt {x: 4, y: 5, z: 6}, ...[Pt {x: 0, y: 1, z: 2}; LEN - 1]] | ||
|
||
def main(private field[ACCESSES] idx) -> field: | ||
field prod = 1 | ||
for u32 i in 0..ACCESSES do | ||
field access = idx[i] | ||
Pt pt = array[access] | ||
prod = prod * pt.x * pt.y * pt.z | ||
endfor | ||
return prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 | ||
(let ( | ||
(idx.0 #f0) | ||
(idx.1 #f1) | ||
(idx.2 #f2) | ||
) false ; ignored | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 | ||
(let ( | ||
(return #f0) | ||
) false ; ignored | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const u32 LEN = 4 | ||
const u32 INNER_LEN = 2 | ||
const u32 ACCESSES = 2 | ||
|
||
struct Pt { | ||
field[INNER_LEN] x | ||
field[INNER_LEN] y | ||
} | ||
const Pt [LEN] array = [Pt {x: [0; INNER_LEN], y: [5; INNER_LEN]}, ...[Pt {x: [1; INNER_LEN], y: [2; INNER_LEN]}; LEN - 1]] | ||
|
||
def main(private field[ACCESSES] idx) -> field: | ||
field prod = 1 | ||
for u32 i in 0..ACCESSES do | ||
field access = idx[i] | ||
Pt pt = array[access] | ||
for u32 j in 0..INNER_LEN do | ||
prod = prod * pt.x[j] * pt.y[j] | ||
endfor | ||
endfor | ||
return prod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 | ||
(let ( | ||
(idx.0 #f0) | ||
(idx.1 #f1) | ||
) false ; ignored | ||
)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 | ||
(let ( | ||
(return #f0) | ||
) false ; ignored | ||
)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const u32 LEN = 256 | ||
const u32 INNER_LEN = 8 | ||
const u32 ACCESSES = 10 | ||
|
||
struct Pt { | ||
field[INNER_LEN] x | ||
field[INNER_LEN] y | ||
} | ||
const Pt [LEN] array = [Pt {x: [0; INNER_LEN], y: [5; INNER_LEN]}, ...[Pt {x: [1; INNER_LEN], y: [2; INNER_LEN]}; LEN - 1]] | ||
|
||
def main(private field[ACCESSES] idx) -> field: | ||
field prod = 1 | ||
for u32 i in 0..ACCESSES do | ||
field access = idx[i] | ||
Pt pt = array[access] | ||
for u32 j in 0..INNER_LEN do | ||
prod = prod * pt.x[j] * pt.y[j] | ||
endfor | ||
endfor | ||
return prod | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env zsh | ||
set -ex | ||
|
||
function usage { | ||
echo "Usage: $0 COMPILER_COMMAND TEMPLATE PATTERN REPLACEMENTS..." | ||
exit 2 | ||
} | ||
|
||
compiler_command=($(eval echo $1)) | ||
template_file=$2 | ||
pattern=$3 | ||
replacements=(${@:4}) | ||
|
||
[[ ! -z $compiler_command ]] || (echo "Empty compiler command" && usage) | ||
if [[ ! -a $template_file ]] | ||
then | ||
for arg in $compiler_command | ||
do | ||
if [[ $arg =~ .*.zok ]] | ||
then | ||
echo "template $arg" | ||
template_file=$arg | ||
fi | ||
done | ||
fi | ||
[[ -a $template_file ]] || (echo "No file at $template_file" && usage) | ||
[[ ! -z $pattern ]] || (echo "Empty pattern" && usage) | ||
[[ ! -z $replacements ]] || (echo "Empty replacements" && usage) | ||
|
||
echo $replacements | ||
|
||
for replacement in $replacements | ||
do | ||
t=$(mktemp compiler_asymptotics_XXXXXXXX.zok) | ||
cat $template_file | sed "s/$pattern/$replacement/g" > $t | ||
instantiated_command=$(echo $compiler_command | sed "s/$template_file/$t/") | ||
echo $instantiated_command | ||
rm $t | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env zsh | ||
|
||
set -ex | ||
|
||
# cargo build --release --features lp,r1cs,smt,zok --example circ | ||
|
||
MODE=debug # release or debug | ||
BIN=./target/$MODE/examples/circ | ||
ZK_BIN=./target/$MODE/examples/zk | ||
|
||
# Test prove workflow, given an example name | ||
function c_pf_test { | ||
proof_impl=groth16 | ||
ex_name=$1 | ||
$BIN examples/C/r1cs/$ex_name.c r1cs --action setup --proof-impl $proof_impl | ||
$ZK_BIN --inputs examples/C/r1cs/$ex_name.c.pin --action prove --proof-impl $proof_impl | ||
$ZK_BIN --inputs examples/C/r1cs/$ex_name.c.vin --action verify --proof-impl $proof_impl | ||
rm -rf P V pi | ||
} | ||
|
||
c_pf_test add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.