Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
6fdf1c8
refactoring and yacc changes
zkronos73 Apr 16, 2023
a13df4e
var scopes, deferred init
zkronos73 Apr 17, 2023
13259ef
wip pil2 language features
zkronos73 Apr 22, 2023
9b2fe30
update grammar
zkronos73 Apr 26, 2023
47cf780
add proto for piloutput
zkronos73 May 1, 2023
97e9f16
update grammar and tests
zkronos73 May 1, 2023
1cb65a0
Workshop LA mo
jbaylina May 2, 2023
c081059
Merge branch 'feature/pil2' of github.com:0xPolygonHermez/pilcom into…
jbaylina May 2, 2023
d545e43
Some more improvements
jbaylina May 2, 2023
a7464b4
Constants in pilout
jbaylina May 2, 2023
57b2582
Small B suggestions
jbaylina May 2, 2023
e5894f8
refactor: subproof section
bobbinth May 3, 2023
c3d93dd
Merge pull request #32 from bobbinth/bobbin-proto-refactor
jbaylina May 4, 2023
3a420f5
More Improvements
jbaylina May 4, 2023
8822c9b
Fix proto bugs
jbaylina May 4, 2023
2eda6e2
renum fields
jbaylina May 4, 2023
e374003
updating test zkevm pil
zkronos73 May 4, 2023
96f7b65
refactor: public table
bobbinth May 5, 2023
d3a8121
refactor: introduce global constraint/expression/operand
bobbinth May 5, 2023
aefe1c2
Merge pull request #33 from bobbinth/bobbin-proto-public-table
jbaylina May 5, 2023
2da5245
Name c
jbaylina May 5, 2023
f6a9b21
continue testing zkevm in pil2
zkronos73 May 5, 2023
a0e608a
fix: message names and comments
bobbinth May 6, 2023
6ac3045
Merge pull request #34 from bobbinth/bobbin-name-fixes
jbaylina May 8, 2023
2252cbd
added function references and prover values
zkronos73 May 8, 2023
909e186
delete incorrect file
zkronos73 May 8, 2023
bfd5905
add std functions and castings, fix minor bugs.
zkronos73 May 9, 2023
f3832ae
fix bugs
zkronos73 May 9, 2023
ed2a603
update public_table example
zkronos73 May 9, 2023
53225fd
update public_table example
zkronos73 May 9, 2023
7ee1b64
continue developing pil2 compiler
zkronos73 May 11, 2023
6ccf841
continue developing, stacked expressions
zkronos73 May 15, 2023
29db4c8
continue developing, stacked expressions
zkronos73 May 15, 2023
d5f2d4f
improvements on expression class
zkronos73 May 16, 2023
ed74226
improvements on assignations, builtin length, proto out
zkronos73 May 23, 2023
8c8709e
asserts on assign.pil and fix bugs
zkronos73 May 23, 2023
255d503
develop pil2 features
zkronos73 May 25, 2023
1c47563
remove obsolete files
zkronos73 May 25, 2023
9d7f626
developing features, fix on toString
zkronos73 May 26, 2023
b9b8cbf
develop packed_expressions
zkronos73 May 26, 2023
1f73f91
add labels on packed expressions
zkronos73 May 26, 2023
c217ea2
fix bug on expresion assigns
zkronos73 May 26, 2023
af9f10a
fibonacci pilout + continue development
zkronos73 May 30, 2023
583f04e
fix time of extend fixed ranges
zkronos73 May 31, 2023
2a83cf4
fix bug on rows extracts
zkronos73 May 31, 2023
520e419
fix some bugs on sequences, develop arith/geom sequences
zkronos73 Jun 2, 2023
fade34c
some tests of sequences
zkronos73 Jun 5, 2023
fec2075
add some sequence tests and clean some logs
zkronos73 Jun 6, 2023
5971e37
add some sequence tests and clean some logs
zkronos73 Jun 6, 2023
48f8625
some tests and fix in expressions
zkronos73 Jun 8, 2023
e057381
feature references
zkronos73 Jun 9, 2023
8280748
feature references
zkronos73 Jun 9, 2023
fe5d325
finish and fix references
zkronos73 Jun 12, 2023
0d64192
update reference test
zkronos73 Jun 12, 2023
6708ebc
feature functions
zkronos73 Jun 13, 2023
d78090e
functions, integers by reference
zkronos73 Jun 14, 2023
483e691
funcions with parcial arrays (subarrays)
zkronos73 Jun 14, 2023
b7022f3
refactoring some classes and compiler structures
zkronos73 Jun 20, 2023
e792231
fix some bugs with function calls
zkronos73 Jun 20, 2023
3d8bcee
updating grammar for subair witness
zkronos73 Jun 20, 2023
ed47b8c
added feature once
zkronos73 Jun 21, 2023
63b7cb1
refactoring builtin functions, globals and more tests
zkronos73 Jun 25, 2023
4ecaf78
example of subairs, some tests.
zkronos73 Jun 30, 2023
306e29e
improvements on subair example and std
zkronos73 Jul 4, 2023
3a2f774
update subair example and std
zkronos73 Jul 4, 2023
54c929d
update pil_parser.js
zkronos73 Jul 4, 2023
cb8c550
update std and public tables
zkronos73 Jul 6, 2023
8be7cdf
Same len std with sums and products done
hecmas Jul 7, 2023
190b8d2
WIP
hecmas Jul 7, 2023
59a3c11
wip
zkronos73 Jul 10, 2023
8067863
Multiset done with new names
hecmas Jul 10, 2023
f1ae751
changes proof,subproof,air and string templates (wip)
zkronos73 Jul 10, 2023
c2d0e4f
update evaluateTemplate, remove logs
zkronos73 Jul 10, 2023
acc7042
remove garbage line on std
zkronos73 Jul 10, 2023
948ac1d
Lookups done
hecmas Jul 11, 2023
b039664
Multisets updated to new version
hecmas Jul 11, 2023
33b6b1c
persistent scopes wip
zkronos73 Jul 11, 2023
dd80143
updates of scopes
zkronos73 Jul 11, 2023
64d69b4
Merge pull request #38 from 0xPolygonHermez/feature/pil2-sum-scope-up…
hecmas Jul 11, 2023
e99a2f3
First version of sums done
hecmas Jul 12, 2023
401188d
Products completed
hecmas Jul 12, 2023
d889afe
WIP
hecmas Jul 12, 2023
c603920
dynamic namespaces wip
zkronos73 Jul 13, 2023
3d66893
WIP
hecmas Jul 13, 2023
e0071e1
Sums done, working in connections
hecmas Jul 13, 2023
afe7b44
container wip
zkronos73 Jul 13, 2023
dcf2284
Adding and optimization to sums
hecmas Jul 13, 2023
631b7c1
Error fixed
hecmas Jul 14, 2023
b560664
Merge pull request #39 from 0xPolygonHermez/feature/pil2-dynamic-name…
zkronos73 Jul 15, 2023
e525a96
const, containers and update proto - WIP
zkronos73 Jul 15, 2023
bb2285b
update proto
zkronos73 Jul 16, 2023
ea66071
resolve merge conflict
zkronos73 Jul 16, 2023
503d35c
Merge pull request #40 from 0xPolygonHermez/feature/pil2-sums
zkronos73 Jul 16, 2023
c0c070f
update last changes on some tests, clear logs.
zkronos73 Jul 17, 2023
de0dead
array (copy) assignation, fix bug double evaluation
zkronos73 Jul 18, 2023
db9efd7
runtime scopes WIP
zkronos73 Jul 18, 2023
0c498f2
fix bugs on assert, fix tests. Containers, uses and aliases
zkronos73 Jul 21, 2023
9c0f889
fix some bugs - WIP
zkronos73 Jul 24, 2023
10f0d09
fix bug on compactStack (simplify expressions)
zkronos73 Jul 24, 2023
70bb309
remove logs and add comments on fixed simplify
zkronos73 Jul 24, 2023
889c3a7
vadcop - fix bugs - deferred calls
zkronos73 Jul 25, 2023
38ebcdf
WIP - fibonacci pilout and other fixs
zkronos73 Jul 27, 2023
6e8c5df
WIP - fibonacci pilout and other fixs
zkronos73 Jul 27, 2023
e38227b
WIP - fibonacci pilout and other fixs
zkronos73 Jul 27, 2023
7c08a57
Small typos and starting to work on human readable format
hecmas Jul 27, 2023
2049ff9
fix bug on expression packing
zkronos73 Jul 30, 2023
1f3cd73
Merge pull request #41 from 0xPolygonHermez/feature/pil2-minor
zkronos73 Jul 30, 2023
04bdc70
fix bug with next
zkronos73 Jul 31, 2023
225f841
add example of transitions
zkronos73 Jul 31, 2023
21e832d
WIP expressions refactoring
zkronos73 Aug 1, 2023
834c2d0
WIP
hecmas Aug 1, 2023
a060d49
fibonacci pil2
zkronos73 Aug 1, 2023
12e1f70
fix bugs on vadcop generation
zkronos73 Aug 1, 2023
459c3b7
Merge pull request #42 from 0xPolygonHermez/feature/pil2-minor
zkronos73 Aug 1, 2023
5bc693a
fix bugs on pilout generation
zkronos73 Aug 2, 2023
3164e4a
fix some bugs on pilout
zkronos73 Aug 2, 2023
95286a0
fix bug with symbols and labels of pilout
zkronos73 Aug 2, 2023
7b55dc7
fix bug on fibonacci and std
zkronos73 Aug 2, 2023
fad0710
WIP
hecmas Aug 2, 2023
50f7da5
Wroking
hecmas Aug 2, 2023
2f56496
fix bugs on pilout generation
zkronos73 Aug 2, 2023
cccea0c
fix bugs on pilout generation
zkronos73 Aug 2, 2023
125c8be
remove alias baseFieldElement usign directly bytes
zkronos73 Aug 3, 2023
74a9c2a
Merge branch 'feature/pil2'
zkronos73 Aug 3, 2023
5d89d73
remove alias baseFieldElement usign directly bytes
zkronos73 Aug 3, 2023
14b1134
WIP
hecmas Aug 3, 2023
da230dc
Constraint printer working
hecmas Aug 4, 2023
447479a
Include in PIL fixed
hecmas Aug 4, 2023
b9e98ea
WIP - refactoring expressions
zkronos73 Aug 4, 2023
b9f6325
subproof definition, execution and multiple
zkronos73 Aug 4, 2023
d8f1b2e
Fix bug that neither challenges or public tables were included as glo…
hecmas Aug 4, 2023
92bb541
subproof definition, execution and multiple
zkronos73 Aug 4, 2023
9c2e332
fix bugs on multisuproof definition
zkronos73 Aug 4, 2023
f66867c
Merge pull request #43 from 0xPolygonHermez/feature/pil2-deferred-sub…
zkronos73 Aug 4, 2023
a6028e6
Merge branch 'feature/pil2'
zkronos73 Aug 4, 2023
72b8a91
Its working, but subproofsIds need to be added to symbols
hecmas Aug 4, 2023
f769bf5
fix bugs on multisuproof definition
zkronos73 Aug 4, 2023
5831e0d
Its working again
hecmas Aug 4, 2023
6ca4442
WIP
zkronos73 Aug 5, 2023
b757b4b
WIP - refactoring expressions
zkronos73 Aug 7, 2023
ed20bc5
WIP - refactoring expressions
zkronos73 Aug 8, 2023
4e0ae6b
WIP
zkronos73 Aug 9, 2023
997949b
WIP - removing invalid code
zkronos73 Aug 10, 2023
8e6514f
fix bug setting on pilout numPublicValues
zkronos73 Aug 10, 2023
eba3926
fix some bugs on pilout generation
zkronos73 Aug 12, 2023
48df805
fix bugs on pilout generation and clean some logs.
zkronos73 Aug 12, 2023
c46d0b5
add stage on symbols needed by witness, challenge
zkronos73 Aug 14, 2023
14c5691
blowupFactor on proto
zkronos73 Aug 14, 2023
a99748b
Merge branch 'feature/pil2' to feature/pil2-expression-refactoring
zkronos73 Aug 14, 2023
0bb18ba
fix bug setting on pilout numPublicValues
zkronos73 Aug 10, 2023
3fa4531
fix some bugs on pilout generation
zkronos73 Aug 12, 2023
d67bbfd
fix bugs on pilout generation and clean some logs.
zkronos73 Aug 12, 2023
bd67beb
add stage on symbols needed by witness, challenge
zkronos73 Aug 14, 2023
799ab81
blowupFactor on proto
zkronos73 Aug 14, 2023
f875a61
WIP
hecmas Aug 2, 2023
02f42d7
Wroking
hecmas Aug 2, 2023
a2566c8
Constraint printer working
hecmas Aug 4, 2023
1b3ee4a
Fix bug that neither challenges or public tables were included as glo…
hecmas Aug 4, 2023
fbeb20e
Its working, but subproofsIds need to be added to symbols
hecmas Aug 4, 2023
6801075
Its working again
hecmas Aug 4, 2023
4c851c4
Now the pilouthr finds symbols by every field. Fixed some minor bugs.
hecmas Aug 21, 2023
40361c8
Merge branch 'feature/pil2' into feature/pil2-minor
zkronos73 Aug 21, 2023
e200321
Fix in sum library
hecmas Aug 21, 2023
af697be
Merge pull request #44 from 0xPolygonHermez/feature/pil2-minor
hecmas Aug 21, 2023
3397f13
Minor changes
hecmas Aug 21, 2023
68984b8
Starting to work on a PIL verifier
hecmas Aug 22, 2023
76da4ea
Working on the pil verifier
hecmas Aug 23, 2023
54fc961
Working on the connection library
hecmas Aug 24, 2023
6b7f313
Working on connections
hecmas Aug 28, 2023
6368ad9
Connection starting to work
hecmas Aug 31, 2023
bd5c538
Connection finally done
hecmas Aug 31, 2023
018da3e
WIP - refactoring expression items and definitions
zkronos73 Sep 2, 2023
3108600
fix prior, next bug when it's numeric
zkronos73 Sep 2, 2023
08e2bee
Fixing buf2bint in proto_out
RogerTaule Sep 4, 2023
c09b895
Adapting polsArray so that works only with ssymbols, not the pil
RogerTaule Sep 4, 2023
febb270
Merge pull request #45 from 0xPolygonHermez/feature/pil2_buf2bintFix
zkronos73 Sep 4, 2023
63af1ed
Merge pull request #46 from 0xPolygonHermez/feature/pil2_polsArray
zkronos73 Sep 4, 2023
e10f05c
add hints support
zkronos73 Sep 12, 2023
5b3462a
Merge pull request #48 from 0xPolygonHermez/feature/pil2-hints
zkronos73 Sep 12, 2023
c76eb2a
Adapting polsArray to work with multiArrays PIL2
RogerTaule Sep 6, 2023
a948cf5
Merge pull request #47 from 0xPolygonHermez/feature/pil2_polsArray
zkronos73 Sep 14, 2023
aa5372f
Working on range checks
hecmas Sep 15, 2023
70d4e27
Range checks working
hecmas Sep 15, 2023
6b2f5bc
Merge branch 'feature/pil2' of into feature/pil2-expression-refactoring
zkronos73 Sep 15, 2023
f2f0a37
Merge pull request #49 from 0xPolygonHermez/feature/pil2-stl
hecmas Sep 19, 2023
d063c73
WIP refactoring
zkronos73 Sep 19, 2023
33b5b32
WIP operators and casting
zkronos73 Sep 19, 2023
db2a833
adding more Exceptions and cast conversions
zkronos73 Sep 20, 2023
752ca07
WIP expressions
zkronos73 Sep 21, 2023
d4626f7
WIP
zkronos73 Sep 24, 2023
03356c0
WIP refactoring and testing
zkronos73 Oct 1, 2023
8f6c89a
WIP const expressions and integers
zkronos73 Oct 2, 2023
e720a83
some fixs to be compatible with previous version of pil2
zkronos73 Oct 3, 2023
c9e5ebf
fix some bugs on pilout
zkronos73 Oct 3, 2023
e01e53f
fix rowOffset on pilout
zkronos73 Oct 3, 2023
eaf2de7
WIP
zkronos73 Oct 18, 2023
0f58edb
Renaming require and provide by assumes and proves, respectively
hecmas Oct 18, 2023
d5c7d7b
Merge pull request #58 from 0xPolygonHermez/feature/require-to-assume
hecmas Oct 18, 2023
0b4d025
WIP
zkronos73 Oct 25, 2023
b50c90e
fix bug with hints references
zkronos73 Oct 28, 2023
c3b87d4
fix hints duplicated
zkronos73 Oct 30, 2023
92845d8
WIP pending finals and pilout errors
zkronos73 Nov 2, 2023
5864a08
WIP, continue testing std
zkronos73 Nov 7, 2023
8c25209
Merge feature/pil2 into feature/pil2-expression-refactoring
zkronos73 Nov 7, 2023
3499539
WIP debugging pilout generation
zkronos73 Nov 7, 2023
2ada145
fix bugs on pilout generation
zkronos73 Nov 10, 2023
be0d73f
WIP - translating etrog to pil2
zkronos73 Jan 4, 2024
11310d3
WIP zkevm-etrog
zkronos73 Jan 30, 2024
f09d001
WIP
zkronos73 Feb 1, 2024
41feddf
WIP pil2
zkronos73 Feb 6, 2024
4c15860
WIP
zkronos73 Feb 19, 2024
d2a5cb4
clean obsolete pils, add README with pil info and fix some compilers …
zkronos73 Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ tmp

.DS_Store
stats.html
package-lock.json
17 changes: 17 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mkdir -p build; ./node_modules/.bin/jison src/pil_parser.jison --debug -o build/pil_parser.js |
tee tmp/states.txt
grep "\->" tmp/states.txt |
sed 's/ ->.*//' |
sort | grep -v "^transitions" |
uniq > /tmp/A
grep -B 400 "^Item sets" tmp/states.txt | grep -v "^transitions " |
grep ".*([0-9]*)" |
sed 's/\(^.*\)([0-9]*).*/\1/' |
sort > /tmp/B
echo -e "\e[31m"
diff --side-by-side /tmp/A /tmp/B | grep "[<|>]" |
sed "s#\([^ ]*\) *[|][ \t]*\([^ ]*\)#< \1\n> \2#g" | sed 's#[ \t]*[><][ \t]*##g' |
grep -vE '(\\\\|\!|\%|\(|\)|\*|\*\=|\+|\+\=|\,|\-|\-\=|\.|\/|\:|\:\:|\=|\=\=\=|\?|\[|\]|\{|\}|\$end|AND|POSITIONAL_PARAM|B_AND|BREAK|B_XOR|CASE|CHALLENGE|COL|CONST|CONTINUE|CS|DEC|DO|DOTS_ARITH_SEQ|DOTS_FILL|DOTS_GEOM_SEQ|DOTS_RANGE|ELSE|EOF|EQ|error|EXPR|FE|FIXED|FOR|FUNCTION|GE|GLOBAL|GT|IDENTIFIER|IF|IN|INC|INCLUDE|INTEGER|IS|LE|LT|METADATA|CONTAINER|NE|NUMBER|OR|POW|PUBLIC|REFERENCE|RETURN|SHL|SHR|STAGE|SWITCH|STRING|TEMPLATE_STRING|T_STRING|WHEN|WHILE|WITNESS|LAST|FIRST|FRAME|ONCE|PROOF|SUBPROOF|SUBPROOF_VALUE|PROOF_VALUE|ALIAS|PRIVATE|ON|AGGREGATE|AIR|USE)' | grep -v "'"
echo -e "\e[0m"


1,217 changes: 989 additions & 228 deletions build/pil_parser.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions docs/expression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# PIL2 (variable, columns, references and others)
All was an expression, perhaps a single expression, but expression.
In this way conversion types are more clear, fromExpression, toExpression.

**References** only was name definition of ...

But arrays? at beggining array was a property associated with name,...

And next?

| Type | To expression | From expression |
|------|---------------|-----------------|
|int||
|fe||
|col witness||
|col fixed||
|expression||
|challenge||
|public||
|air value||
|subair value||
|number||
|list||

- **instance()** make a copy of expression, where __runtime values and expressions__ (variables, eq, be) are replaced
- **evaluate()** calculate a single value (int, fe, bool) without replacing runtime values and expressions. For example, a condition on loop, etc..

```mermaid
classDiagram
ExpressionItem <-- RuntimeItem
ExpressionItem <-- ProofItem
RuntimeItem <-- ReferenceItem
RuntimeItem <-- ExpressionReference
RuntimeItem <-- ValueItem
RuntimeItem <-- StringValue
RuntimeItem <-- FunctionCall
ProofItem <-- Challenge
ProofItem <-- ProofVal
ProofItem <-- FixedCol
ProofItem <-- WitnessCol
ProofItem <-- Public
ProofItem <-- SubproofVal
ValueItem <-- IntValue
ValueItem <-- FeValue
``````
162 changes: 162 additions & 0 deletions lib/std_prod.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
function init_challenges(int extra) {
once {
global challenge std_alpha stage(2);
global challenge std_beta stage(2);
global challenge std_gamma stage(3);
}
if (extra) {
once global challenge std_delta stage(3);
}
}

function init_coset_constants(int len) {
global std_ks[len];

for (int i = 0; i < len; ++i) {
std_ks[i] = global constant k[i];
}
}

/**
* Given two multisets A and B, check whether A is equal to B.
* @param selF selector to decide which elements of colsF are included in multiset A
* @param colsF columns to be included in multiset A
* @param selT selector to decide which elements of colsT are included in multiset B
* @param colsT columns to be included in multiset B
* @return Constraints to be satisfied by A and B to ensure the multiset check
*/
function multiset_check(expr selF, expr colsF[], expr selT, expr colsT[]) {
// TODO: use specific name, not match with other challenge
init_challenges(0);
if (length(colsF) != length(colsT)) {
error(`colsF and colsT must be same dimensions`);
}

// TODO: optimize to put only once this constraint if witness col, if cols are fixed
// check on compilation time, constraint not needed.

// TODO: verify if selF or selT is constant value 1 or 0, if 1 no need these constraints
selF * (1 - selF) === 0;
selT * (1 - selT) === 0;

col fixed L1 = [1,0...]; // compiler optimize and only exists one L1

// global is visible inside function vs static
expr colsF_compressed = 0;
expr colsT_compressed = 0;
for (int icol = length(colsF) - 1; icol > 0; --icol) {
colsF_compressed = (colsF_compressed + colsF[icol]) * std_alpha;
colsT_compressed = (colsT_compressed + colsT[icol]) * std_alpha;
}
colsF_compressed = (colsF_compressed + colsF[0]);
colsT_compressed = (colsT_compressed + colsT[0]);

expr colsF_selected = selF * (colsF_compressed - std_beta) + std_beta;
expr colsT_selected = selT * (colsT_compressed - std_beta) + std_beta;

// TODO: allow use defined constants as stage id.
col witness gprod stage(3);

// (colsF_selected + std_gamma)
// gprod' === gprod * ----------------------------
// (colsT_selected + std_gamma)

L1 * (gprod - 1) === 0;
gprod' * (colsT_selected + std_gamma) === gprod * (colsF_selected + std_gamma);
}

/**
* Given two multisets A and B, check whether A is a subset of B (viewed as sets).
* @param selF selector to decide which elements of colsF are included in multiset A
* @param colsF columns to be included in multiset A
* @param selT selector to decide which elements of colsT are included in multiset B
* @param colsT columns to be included in multiset B
* @return Constraints to be satisfied by A and B to ensure the lookup check
*/
function lookup_check(col selF, expr colsF[], col selT, expr colsT[]) {
init_challenges(1);
if (length(colsF) != length(colsT)) {
error(`colsF and colsT must be same dimensions`);
}

// TODO: optimize to put only once this constraint if witness col, if cols are fixed
// check on compilation time, constraint not needed.
selF * (1 - selF) === 0;
selT * (1 - selT) === 0;

col fixed L1 = [1,0...]; // compiler optimize and only exists one L1

// global is visible inside function vs static
expr colsF_compressed = 0;
expr colsT_compressed = 0;
for (int icol = length(colsF) - 1; icol > 0; --icol) {
colsF_compressed = (colsF_compressed + colsF[icol]) * std_alpha;
colsT_compressed = (colsT_compressed + colsT[icol]) * std_alpha;
}
colsF_compressed = (colsF_compressed + colsF[0]);
colsT_compressed = (colsT_compressed + colsT[0]);

expr colsT_selected = selT * (colsT_compressed - std_beta) + std_beta;
expr colsF_selected = selF * (colsF_compressed - colsT_selected) + colsT_selected;

// @lookup_check {h1:h1, h2:h2, colsT: colsT_selected, colsF: colsF_selected, gprod: gprod };

@lookup_check {h1, h2, colsT: colsT_selected, colsF: colsF_selected, gprod};

// Define h1,h2 polynomials
col witness h1 stage(2);
col witness h2 stage(2);

// TODO: allow use defined constants as stage id.
col witness gprod stage(3);

// (1 + gamma) * (f + delta) * (delta*(1 + gamma) + t + gamma*t')
// gprod' === gprod * ------------------------------------------------------------------------------------
// (delta*(1 + gamma) + h1 + gamma*h2) * (delta*(1 + gamma) + h2 + gamma*h1')

L1 * (gprod - 1) === 0;
gprod' * (std_delta*(1 + std_gamma) + h1 + std_gamma*h2) * (std_delta*(1 + std_gamma) + h2 + std_gamma*h1') === gprod * (1 + std_gamma) * (colsF_selected + std_delta) * (std_delta*(1 + std_gamma) + colsT_selected + std_gamma*colsT_selected');
}

/**
* Given multisets A1,...,An and B1,...,Bn, check whether A1,...,An does not vary
* after applying the permutation B1,...,Bn to itself.
* @param cols columns subject to the permutation
* @param Sperms columns defining the permutation
* @return Constraints to be satisfied by A and B to ensure the connection check
*/
function connection_check(expr cols[], expr Sperms[]) {
constant len = length(cols);

init_challenges(1);
init_coset_constants(len);

if (len != length(Sperms)) {
error(`cols and Sperms must be same dimensions`);
}

col fixed L1 = [1,0...];
col fixed IDEN = [1,omega,..*..,omega**(N-1)];

col witness gprod stage(3);

// Define SIDs[i] = k_i·X polynomials
expr SIDs[len];
for (int icol = 0; icol < len; ++icol) {
SIDs[icol] = std_ks[icol] * IDEN;
}

// (f_0 + gamma·X + delta) · (f_1 + gamma·k_1·X + delta) · ... · (f_N + gamma·k_n·X + delta)
// gprod' === gprod * -------------------------------------------------------------------------------------------
// (f_0 + gamma·S_0 + delta) · (f_1 + gamma·S_1 + delta) · ... · (f_N + gamma·S_n + delta)

expr numerator = 1;
expr denominator = 1;
for (int icol = 0; icol < len; ++icol) {
numerator = numerator * (cols[icol] + std_gamma*SIDs[icol] + std_delta);
denominator = denominator * (cols[icol] + std_gamma*Sperms[icol] + std_delta);
}

L1 * (gprod - 1) === 0;
gprod' * denominator === gprod * numerator;
}
151 changes: 151 additions & 0 deletions lib/std_sum.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
function init_challenges(int extra) {
once proof {
challenge stage(2) std_alpha;
challenge stage(2) std_beta;
challenge stage(3) std_gamma;
}
if (extra) {
once proof challenge stage(3) std_delta;
}
}

function init_coset_constants(int len) {
const int std_ks[len];
// int std_ks[len];

for (int i = 0; i < len; ++i) {
// std_ks[i] = constant k[i];
}
}

/**
* Given two multisets A and B, check whether A is equal to B.
* @param selF selector to decide which elements of colsF are included in multiset A
* @param colsF columns to be included in multiset A
* @param selT selector to decide which elements of colsT are included in multiset B
* @param colsT columns to be included in multiset B
* @return Constraints to be satisfied by A and B to ensure the multiset check
*/
function multiset_check(expr selF, expr colsF[], expr selT, expr colsT[]) {
init_challenges(0);
if (length(colsF) != length(colsT)) {
error(`colsF and colsT must be same dimensions`);
}

selF * (1 - selF) === 0;
selT * (1 - selT) === 0;

col fixed L1 = [1,0...];

expr colsF_compressed = 0;
expr colsT_compressed = 0;
for (int icol = length(colsF) - 1; icol > 0; --icol) {
colsF_compressed = (colsF_compressed + colsF[icol]) * std_alpha;
colsT_compressed = (colsT_compressed + colsT[icol]) * std_alpha;
}
colsF_compressed = (colsF_compressed + colsF[0]);
colsT_compressed = (colsT_compressed + colsT[0]);

expr colsF_selected = selF * (colsF_compressed - std_beta) + std_beta;
expr colsT_selected = selT * (colsT_compressed - std_beta) + std_beta;

col witness stage(3) gsum;

// 1 1
// gsum' === gsum + ---------------------------- - ----------------------------
// (colsT_selected + std_gamma) (colsF_selected + std_gamma)

L1 * gsum === 0;
(gsum' - gsum) * (colsT_selected + std_gamma) * (colsF_selected + std_gamma) === (colsF_selected + std_gamma) - (colsT_selected + std_gamma);
}

/**
* Given two multisets A and B, check whether A is a subset of B (viewed as sets).
* @param selF selector to decide which elements of colsF are included in multiset A
* @param colsF columns to be included in multiset A
* @param selT selector to decide which elements of colsT are included in multiset B
* @param colsT columns to be included in multiset B
* @return Constraints to be satisfied by A and B to ensure the lookup check
*/
function lookup_check(expr selF, expr colsF[], expr selT, expr colsT[]) {
init_challenges(1);
if (length(colsF) != length(colsT)) {
error(`colsF and colsT must be same dimensions`);
}

selF * (1 - selF) === 0;
selT * (1 - selT) === 0;

col fixed L1 = [1,0...];

expr colsF_compressed = 0;
expr colsT_compressed = 0;
for (int icol = length(colsF) - 1; icol > 0; --icol) {
colsF_compressed = (colsF_compressed + colsF[icol]) * std_alpha;
colsT_compressed = (colsT_compressed + colsT[icol]) * std_alpha;
}
colsF_compressed = (colsF_compressed + colsF[0]);
colsT_compressed = (colsT_compressed + colsT[0]);

expr colsT_selected = selT * (colsT_compressed - std_beta) + std_beta;
expr colsF_selected = selF * (colsF_compressed - colsT_selected) + colsT_selected;

// Define the (normalized) multiplicity polynomial m:
// |j ∈ [N]: colsF_selected_j = colsT_selected_i|
// m_i = ----------------------------------------------
// |j ∈ [N]: colsT_selected_j = colsT_selected_i|
@lookup_check {m: m, colsT: colsT_selected, colsF: colsF_selected, gsum: gsum };
col witness stage(2) m;

col witness stage(3) gsum;

// m 1
// gsum' === gsum + ---------------------------- - ----------------------------
// (colsT_selected + std_gamma) (colsF_selected + std_gamma)

L1 * gsum === 0;
(gsum' - gsum) * (colsT_selected + std_gamma) * (colsF_selected + std_gamma) === m * (colsF_selected + std_gamma) - (colsT_selected + std_gamma);
}

/**
* Given multisets A1,...,An and B1,...,Bn, check whether A1,...,An does not vary
* after applying the permutation B1,...,Bn to itself.
* @param cols columns subject to the permutation
* @param Sperms columns defining the permutation
* @return Constraints to be satisfied by A and B to ensure the connection check
*/
function connection_check(expr cols[], expr Sperms[]) {
const int len = length(cols);

init_challenges(1);
init_coset_constants(len);

if (len != length(Sperms)) {
error(`cols and Sperms must be same dimensions`);
}

col fixed L1 = [1,0...];
col fixed IDEN = [1,omega..*..omega**(N-1)];

col witness stage(3) gsum;

// Define SIDs[i] = k_i·X polynomials
expr SIDs[len];
for (int icol = 0; icol < len; ++icol) {
SIDs[icol] = std_ks[icol] * IDEN;
}

// 1 1
// gsum' === gsum + ----------------------------------------------------------- - -----------------------------------------------------------
// (f_0 + gamma·X + delta) · ... · (f_N + gamma·k_2·X + delta) (f_0 + gamma·S_0 + delta) · ... · (f_N + gamma·S_n + delta)

expr first_summand = 1;
expr second_summand = 1;
for (int icol = 0; icol < len; ++icol) {
first_summand = first_summand * (cols[icol] + std_gamma*SIDs[icol] + std_delta);
second_summand = second_summand * (cols[icol] + std_gamma*Sperms[icol] + std_delta);
}

L1 * gsum === 0;
(gsum' - gsum) * first_summand * second_summand === second_summand - first_summand;
}
Loading