-
Notifications
You must be signed in to change notification settings - Fork 18
/
staticVariables.ts
120 lines (110 loc) · 3.16 KB
/
staticVariables.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// IMPORTS
// ================================================================================================
import { instantiateScript } from '../../index';
import { Logger } from '../../lib/utils';
// STARK DEFINITION
// ================================================================================================
const steps = 2**6, result = 780n;
const demoStark = instantiateScript(Buffer.from(`
define Demo over prime field (96769) {
static k0: cycle [1, 2, 3, 4];
static k1: cycle [1, 2, 3, 4, 5, 6, 7, 8];
secret input startValue: element[1];
transition 1 register {
for each (startValue) {
init { yield startValue; }
for steps [1..${steps - 1}] {
yield $r0 + 1 + k0 + 2 * k1;
}
}
}
enforce 1 constraint {
for all steps {
enforce transition($r) = $n;
}
}
}`), undefined, new Logger(false));
// TESTING
// ================================================================================================
// set up inputs and assertions
const inputs = [[1n]];
const assertions = [
{ step: 0, register: 0, value: inputs[0][0] },
{ step: steps-1, register: 0, value: result }
];
// generate a proof
const proof = demoStark.prove(assertions, inputs);
console.log('-'.repeat(20));
// verify the proof
demoStark.verify(assertions, proof);
console.log('-'.repeat(20));
// EXECUTION TRACE
// ================================================================================================
// K0 is the first static variables, K1 is the second static,
// V0 is the trace register. The transition function is vNext = v0 + 1 + K0 + 2 * K1
//
// Step K0 K1 V0
// 0 1 1 1
// 1 2 2 5
// 2 3 3 12
// 3 4 4 22
// 4 1 5 35
// 5 2 6 47
// 6 3 7 62
// 7 4 8 80
// 8 1 1 101
// 9 2 2 105
// 10 3 3 112
// 11 4 4 122
// 12 1 5 135
// 13 2 6 147
// 14 3 7 162
// 15 4 8 180
// 16 1 1 201
// 17 2 2 205
// 18 3 3 212
// 19 4 4 222
// 20 1 5 235
// 21 2 6 247
// 22 3 7 262
// 23 4 8 280
// 24 1 1 301
// 25 2 2 305
// 26 3 3 312
// 27 4 4 322
// 28 1 5 335
// 29 2 6 347
// 30 3 7 362
// 31 4 8 380
// 32 1 1 401
// 33 2 2 405
// 34 3 3 412
// 35 4 4 422
// 36 1 5 435
// 37 2 6 447
// 38 3 7 462
// 39 4 8 480
// 40 1 1 501
// 41 2 2 505
// 42 3 3 512
// 43 4 4 522
// 44 1 5 535
// 45 2 6 547
// 46 3 7 562
// 47 4 8 580
// 48 1 1 601
// 49 2 2 605
// 50 3 3 612
// 51 4 4 622
// 52 1 5 635
// 53 2 6 647
// 54 3 7 662
// 55 4 8 680
// 56 1 1 701
// 57 2 2 705
// 58 3 3 712
// 59 4 4 722
// 60 1 5 735
// 61 2 6 747
// 62 3 7 762
// 63 4 8 780