-
Notifications
You must be signed in to change notification settings - Fork 18
/
genstark.d.ts
175 lines (143 loc) · 7.49 KB
/
genstark.d.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
declare module '@guildofweavers/genstark' {
// IMPORTS
// --------------------------------------------------------------------------------------------
import { Matrix } from '@guildofweavers/galois';
import { AirSchema, FiniteField, AirModule } from '@guildofweavers/air-assembly';
import { Hash, HashAlgorithm, BatchMerkleProof } from '@guildofweavers/merkle';
// RE-EXPORTS
// --------------------------------------------------------------------------------------------
export { FiniteField, createPrimeField, Vector, Matrix } from '@guildofweavers/galois';
export { MerkleTree, BatchMerkleProof, HashAlgorithm, createHash, Hash } from '@guildofweavers/merkle';
// PUBLIC FUNCTIONS
// --------------------------------------------------------------------------------------------
/**
* Creates an instance of STARK object based on the provided AirAssembly schema.
* @param schema AirAssembly schema from which the STARK object is to be built.
* @param component Name of the component from which to instantiate STARK. If omitted 'default` will be used.
* @param options Security and optimization options for STARK instance.
* @param logger Optional logger; defaults to console logging; set to null to disable.
*/
export function instantiate(schema: AirSchema, component: string, options?: Partial<StarkOptions>, logger?: Logger | null): Stark;
/**
* Creates an instance of STARK object from the provided AirAssembly source code.
* @param source AirAssembly source code from which the STARK object is to be built.
* @param component Name of the component from which to instantiate STARK. If omitted 'default` will be used.
* @param options Security and optimization options for STARK instance.
* @param logger Optional logger; defaults to console logging; set to null to disable.
*/
export function instantiate(source: Buffer, component: string, options?: Partial<StarkOptions>, logger?: Logger | null): Stark;
/**
* Creates an instance of STARK object from the specified AirAssembly file.
* @param path Path to a file containing AirAssembly source code from which the STARK object is to be built.
* @param component Name of the component from which to instantiate STARK. If omitted 'default` will be used.
* @param options Security and optimization options for STARK instance.
* @param logger Optional logger; defaults to console logging; set to null to disable.
*/
export function instantiate(path: string, component: string, options?: Partial<StarkOptions>, logger?: Logger | null): Stark;
/**
* Creates an instance of STARK object from the provided AirScript source code.
* @param source AirScript source code from which the STARK object is to be built.
* @param options Security and optimization options for STARK instance.
* @param logger Optional logger; defaults to console logging; set to null to disable.
*/
export function instantiateScript(source: Buffer, options?: Partial<StarkOptions>, logger?: Logger): Stark;
/**
* Creates an instance of STARK object from the specified AirAssembly file.
* @param path Path to a file containing AirScript source code from which the STARK object is to be built.
* @param component Name of the component from which to instantiate STARK. If omitted 'default` will be used.
* @param logger Optional logger; defaults to console logging; set to null to disable.
*/
export function instantiateScript(path: string, options?: Partial<StarkOptions>, logger?: Logger): Stark;
// STARK
// --------------------------------------------------------------------------------------------
export interface StarkOptions extends SecurityOptions {
/** A flag indicating whether to use WebAssembly optimizations; defaults to true */
readonly wasm: boolean;
}
export interface SecurityOptions {
/**
* Execution trace extension factor; defaults to the smallest power of 2 greater than 2x
* of the highest constraint degree
*/
readonly extensionFactor: number;
/** Number of queries for the execution trace; defaults to 80 */
readonly exeQueryCount: number;
/** Number of queries for low degree proof; defaults to 40 */
readonly friQueryCount: number;
/** Hash algorithm for Merkle trees; defaults to sha256 */
readonly hashAlgorithm: HashAlgorithm;
}
export interface Stark {
/** AIR from which this STARK was built */
readonly air: AirModule;
/** Estimated security level of the STARK (experimental) */
readonly securityLevel: number;
/**
* Generate a proof of computation for this STARK.
* @param assertions Boundary constraints for the computation.
* @param inputs Values for initializing all declared input.
* @param seed Seed values for initializing execution trace.
*/
prove(assertions: Assertion[], inputs?: any[], seed?: bigint[]): StarkProof;
/**
* Verifies a proof of computation for this STARK.
* @param assertions Boundary constraints for the computation.
* @param proof Proof of the computation.
* @param publicInputs Values for initializing declared public inputs.
*/
verify(assertions: Assertion[], proof: StarkProof, publicInputs?: any[]): boolean;
/**
* Generates execution trace tables for the computation.
* @param inputs Values for initializing all declared input.
* @param seed Seed values for initializing execution trace.
*/
generateExecutionTrace(inputs?: any[], seed?: bigint[]): { dTrace: Matrix; sTrace: Matrix; };
/** Returns the size in bytes for the provided proof */
sizeOf(proof: StarkProof): number;
/** Writes the proof to a buffer */
serialize(proof: StarkProof): Buffer;
/** Reads a proof from the provided buffer */
parse(proof: Buffer): StarkProof;
}
export interface StarkProof {
evRoot : Buffer;
evProof : BatchMerkleProof;
ldProof : LowDegreeProof;
iShapes : number[][];
}
// CONSTRAINTS
// --------------------------------------------------------------------------------------------
export interface Assertion {
/** index of a mutable register */
register: number;
/** step in the execution trace */
step: number;
/** value that the register should have at the specified step */
value: bigint;
}
// LOW DEGREE PROOF
// --------------------------------------------------------------------------------------------
export interface LowDegreeProof {
lcRoot : Buffer;
lcProof : BatchMerkleProof,
components : FriComponent[];
remainder : bigint[];
}
export interface FriComponent {
columnRoot : Buffer;
columnProof : BatchMerkleProof;
polyProof : BatchMerkleProof;
}
// UTILITIES
// --------------------------------------------------------------------------------------------
export const inline: {
vector(v: bigint[]): string;
matrix(m: bigint[][]): string;
};
export interface Logger {
start(message?: string, prefix?: string) : LogFunction;
sub(message?: string): LogFunction;
done(log: LogFunction, message?: string): void;
}
export type LogFunction = (message: string) => void;
}