Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 36 additions & 37 deletions test/pil2/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,17 @@


```
challenge alfa stage 2;
challenge alfa stage 2;

pol commit z stage 1;

pol commit z stage 1;
pol commit a; // equivalent to `pol commit a stage 1`

pol commit a; // equivalent to `pol commit a stage 1`
// Optional
pol commit z[10] stage 3;

// Optional
pol commit z[10] stage 3;

// Optional (Not in first version)
challenge ys[12]{0..31} stage 3;
// Optional (Not in first version)
challenge ys[12]{0..31} stage 3;

````

Expand All @@ -89,25 +88,25 @@ pol is committed at stage 2 (it is available from this stage)
## Conditionals constraints

```
// Proposal 1
(1- L1) { b*c === a };
// Proposal 1
(1- L1) { b*c === a };

// Proposal 2 THE GOOD ONE
when L1 { a === a'; };
when 1-L1 { a === b*c; };
// Proposal 2 THE GOOD ONE
when L1 { a === a'; };
when 1-L1 { a === b*c; };

d == e*f' when 1- LLAST
d == e*f' when 1- LLAST

defaultwhen 1-LLAST
defaultwhen 1-LLAST

when L1 {
a === a';
b === b';
};
when L1 {
a === a';
b === b';
};

// Actual way
L1* (a' -a) === 0;
(1-L1)* (b*c -a) === 0;
// Actual way
L1* (a' -a) === 0;
(1-L1)* (b*c -a) === 0;

```
selector binary.
Expand Down Expand Up @@ -263,7 +262,6 @@ namespace Ninetoone subproof keccak

## Prior and next N
```

<n>'<pol>
<pol>'<n>

Expand Down Expand Up @@ -302,27 +300,28 @@ m0[7]' = (1-RESET) * m0[7] + FACTOR'28 * inM[0];
for (var i=0; i<7; ++i {
m0[i]' === (1-RESET) * m0[i] + FACTOR'(i*4) * inM[0];
})

```

## Range checks

```
sel { a } in [0..255];

sel { a } in [0..255];

a in [0..255];
b in [0..255];
a in [0..255];
b in [0..255];
```

## Connect

```
setIdentity(S[0],S[1],S[2]); // setIdentity is a buildin function

setIdentity(S[0],S[1],S[2]); // setIdentity is a buildin function

function connect(ref S1, var p1, ref S2, var p2) {
var tmp = S1[p1];
S1[p1] = S2[p2];
S2[p2] = tmp;
}
function connect(ref S1, var p1, ref S2, var p2) {
var tmp = S1[p1];
S1[p1] = S2[p2];
S2[p2] = tmp;
}
```


## Constant Optimizations
Expand All @@ -338,12 +337,13 @@ prime


## NOTES

- constants could be change with N, in subproof could define multiple N needs to compute all for each N.
- expressions could change if has an variable or reference inside.

## NOTES builtin
degree(expression)

degree(expression)

### template expressions

Expand All @@ -365,7 +365,6 @@ assert(params(e) == 1);

e = e(col2); // e = a * col0 + b * col1 + col2
assert(params(e) == 0);

```

expression(param0, param1, param2) = internally is a clone and param0, ....
Expand Down
6 changes: 4 additions & 2 deletions test/pil2/components/expression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe("Expression", async function () {
this.timeout(10000000);

it("Basic test", async () => {

// 1. OP_VALUE = 0
let e = new Expression();
assert.equal(e.isAlone(), false);

Expand All @@ -25,6 +27,7 @@ describe("Expression", async function () {
let expected = [{op: false, operands: [{type: 0, value: 0}]}];
assert.equal(toJSON(e.stack), toJSON(expected));

// 2. OP_RUNTIME = 3
e = new Expression();

assert.equal(e.isAlone(), false);
Expand All @@ -39,6 +42,7 @@ describe("Expression", async function () {
expected = [{op: false, operands: [{type: 3, name: 'joe', indexes: [5], next: 7}]}];
assert.equal(toJSON(e.stack), toJSON(expected));

// 3. OP_ID_REF = 1
e = new Expression();

assert.equal(e.isAlone(), false);
Expand Down Expand Up @@ -141,8 +145,6 @@ describe("Expression", async function () {
let d2 = new Expression();
d2.setIdReference(103, 'fe', -18746, 0);



let d = new Expression();
d.insert('+', d1, d2);
let expectedD = [{op:'+',operands:[{type:3, name: 'JohnSmith', indexes: [2, 5, 7], next: 10},
Expand Down
16 changes: 7 additions & 9 deletions test/pil2/features/once.pil
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
subair Functions(2**23);

function func_with_once (col &p1) {
once p1 === 314;
function func_with_once (col witness p1) {
once subproof p1 === 314;
}

function func_with_once2 (int i) : int {
println(i);
once int j = 13;
once subproof int j = 13;
return i * j;
}

namespace Functions:: {
subproof Functions(2**23) {

col witness c1,c2;

Expand All @@ -19,19 +17,19 @@ namespace Functions:: {

for (int i = 1; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
once c2 + c1 === i * j * 7;
once subproof c2 + c1 === i * j * 7;
}
}

for (int i = 2; i < 5; ++i) {
once {
once subproof {
for (int j = i + 1; j < 5; ++j) {
c2 + c1 === i * j * 11;
}
}
}

once {
once subproof {
for (int i = 3; i < 5; ++i) {
for (int j = i + 1; j < 7; ++j) {
c2 + c1 === i * j;
Expand Down