@guildofweavers/genstark
Advanced tools
Comparing version 0.5.5 to 0.5.6
@@ -131,5 +131,5 @@ declare module '@guildofweavers/genstark' { | ||
export interface Logger { | ||
start(message?: string, prefix?: string) : symbol; | ||
log(label: symbol, message: string): void; | ||
done(label: symbol, message?: string): void; | ||
start(message?: string, prefix?: string) : LogFunction; | ||
sub(message?: string): LogFunction; | ||
done(log: LogFunction, message?: string): void; | ||
} | ||
@@ -136,0 +136,0 @@ |
@@ -25,3 +25,3 @@ "use strict"; | ||
// -------------------------------------------------------------------------------------------- | ||
prove(cEvaluations, domain, exeQueryPositions, maxDegreePlus1) { | ||
prove(cEvaluations, domain, maxDegreePlus1) { | ||
// transpose composition polynomial evaluations into a matrix with 4 columns | ||
@@ -34,2 +34,3 @@ const polyValues = this.field.transposeVector(cEvaluations, 4); | ||
// build Merkle proofs but swap out hashed values for the un-hashed ones | ||
const exeQueryPositions = this.idxGenerator.getExeIndexes(pTree.root, domain.length); | ||
const lcPositions = getAugmentedPositions(exeQueryPositions, cEvaluations.length); | ||
@@ -36,0 +37,0 @@ const lcProof = pTree.proveBatch(lcPositions); |
@@ -73,4 +73,3 @@ "use strict"; | ||
prove(assertions, initValues, publicInputs, secretInputs) { | ||
const label = this.logger.start('Starting STARK computation'); | ||
const log = this.logger.log.bind(this.logger, label); | ||
const log = this.logger.start('Starting STARK computation'); | ||
// 0 ----- validate parameters | ||
@@ -110,26 +109,19 @@ if (!Array.isArray(assertions)) | ||
log('Built evaluation merkle tree'); | ||
// 5 ----- query evaluation tree at pseudo-random positions | ||
const positions = this.indexGenerator.getExeIndexes(eTree.root, evaluationDomainSize); | ||
const augmentedPositions = this.getAugmentedPositions(positions, evaluationDomainSize); | ||
const eValues = this.mergeValues(eVectors, augmentedPositions); | ||
const eProof = eTree.proveBatch(augmentedPositions); | ||
eProof.values = eValues; | ||
log(`Computed ${positions.length} evaluation spot checks`); | ||
// 6 ----- compute composition polynomial C(x) | ||
//const cLabel = this.logger.start('Computing composition polynomial', ' '); | ||
//const cLogger = this.logger.log.bind(this.logger, cLabel); | ||
const cPoly = new components_1.CompositionPolynomial(this.air.constraints, assertions, eTree.root, context, utils_1.noop); | ||
// 5 ----- compute composition polynomial C(x) | ||
const cLogger = this.logger.sub('Computing composition polynomial'); | ||
const cPoly = new components_1.CompositionPolynomial(this.air.constraints, assertions, eTree.root, context, cLogger); | ||
const cEvaluations = cPoly.evaluateAll(pPolys, pEvaluations, context); | ||
this.logger.done(cLogger); | ||
log('Computed composition polynomial C(x)'); | ||
// 7 ---- compute random linear combination of evaluations | ||
// 6 ---- compute random linear combination of evaluations | ||
const lCombination = new components_1.LinearCombination(eTree.root, cPoly.compositionDegree, cPoly.coefficientCount, context); | ||
const lEvaluations = lCombination.computeMany(cEvaluations, pEvaluations, sEvaluations); | ||
log('Combined P(x) and S(x) evaluations with C(x) evaluations'); | ||
// 8 ----- Compute low-degree proof | ||
// 7 ----- Compute low-degree proof | ||
let ldProof; | ||
try { | ||
//const ldLabel = this.logger.start('Computing low degree proof', ' '); | ||
//const ldLogger = this.logger.log.bind(this.logger, ldLabel); | ||
const ldProver = new components_1.LowDegreeProver(this.indexGenerator, this.hash, context, utils_1.noop); | ||
ldProof = ldProver.prove(lEvaluations, context.evaluationDomain, positions, cPoly.compositionDegree); | ||
const ldLogger = this.logger.sub('Computing low degree proof'); | ||
const ldProver = new components_1.LowDegreeProver(this.indexGenerator, this.hash, context, ldLogger); | ||
ldProof = ldProver.prove(lEvaluations, context.evaluationDomain, cPoly.compositionDegree); | ||
this.logger.done(ldLogger); | ||
log('Computed low-degree proof'); | ||
@@ -140,3 +132,10 @@ } | ||
} | ||
this.logger.done(label, 'STARK computed'); | ||
// 8 ----- query evaluation tree at pseudo-random positions | ||
const positions = this.indexGenerator.getExeIndexes(ldProof.lcRoot, evaluationDomainSize); | ||
const augmentedPositions = this.getAugmentedPositions(positions, evaluationDomainSize); | ||
const eValues = this.mergeValues(eVectors, augmentedPositions); | ||
const eProof = eTree.proveBatch(augmentedPositions); | ||
eProof.values = eValues; | ||
log(`Computed ${positions.length} evaluation spot checks`); | ||
this.logger.done(log, 'STARK computed'); | ||
// build and return the proof object | ||
@@ -152,4 +151,3 @@ return { | ||
verify(assertions, proof, publicInputs) { | ||
const label = this.logger.start('Starting STARK verification'); | ||
const log = this.logger.log.bind(this.logger, label); | ||
const log = this.logger.start('Starting STARK verification'); | ||
// 0 ----- validate parameters | ||
@@ -168,3 +166,3 @@ if (assertions.length < 1) | ||
// 2 ----- compute positions for evaluation spot-checks | ||
const positions = this.indexGenerator.getExeIndexes(eRoot, evaluationDomainSize); | ||
const positions = this.indexGenerator.getExeIndexes(proof.ldProof.lcRoot, evaluationDomainSize); | ||
const augmentedPositions = this.getAugmentedPositions(positions, evaluationDomainSize); | ||
@@ -220,3 +218,3 @@ log(`Computed positions for evaluation spot checks`); | ||
log(`Verified low-degree proof`); | ||
this.logger.done(label, 'STARK verified'); | ||
this.logger.done(log, 'STARK verified'); | ||
return true; | ||
@@ -223,0 +221,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("./index"); | ||
// CLASS DEFINITION | ||
@@ -8,5 +9,7 @@ // ================================================================================================ | ||
// -------------------------------------------------------------------------------------------- | ||
constructor() { | ||
constructor(enableSubLog = true) { | ||
this.functionMap = new Map(); | ||
this.timestampMap = new Map(); | ||
this.prefixMap = new Map(); | ||
this.enableSubLog = enableSubLog; | ||
} | ||
@@ -23,4 +26,28 @@ // PUBLIC METHODS | ||
this.prefixMap.set(label, prefix || ''); | ||
return label; | ||
const log = this.log.bind(this, label); | ||
this.functionMap.set(log, label); | ||
return log; | ||
} | ||
sub(message) { | ||
if (this.enableSubLog) { | ||
return this.start(message, ' '); | ||
} | ||
else { | ||
return index_1.noop; | ||
} | ||
} | ||
done(log, message) { | ||
if (log === index_1.noop) | ||
return; | ||
const label = this.functionMap.get(log); | ||
const [start] = this.timestampMap.get(label); | ||
if (message) { | ||
console.log(`${message} in ${Date.now() - start} ms`); | ||
} | ||
this.functionMap.delete(log); | ||
this.timestampMap.delete(label); | ||
this.prefixMap.delete(label); | ||
} | ||
// PRIVATE METHODS | ||
// -------------------------------------------------------------------------------------------- | ||
log(label, message) { | ||
@@ -32,11 +59,4 @@ const [start, ts] = this.timestampMap.get(label); | ||
} | ||
done(label, message) { | ||
const [start] = this.timestampMap.get(label); | ||
this.timestampMap.delete(label); | ||
if (message) { | ||
console.log(`${message} in ${Date.now() - start} ms`); | ||
} | ||
} | ||
} | ||
exports.Logger = Logger; | ||
//# sourceMappingURL=Logger.js.map |
{ | ||
"name": "@guildofweavers/genstark", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"description": "zk-STARK generation library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -214,4 +214,4 @@ # genSTARK | ||
| Merkle Proof (Rescue, d=16) | 128 bits | 4 | 8 | 2<sup>9</sup> | 1.1 sec | 63 KB | | ||
| Merkle Proof (Poseidon, d=8) | 128 bits | 7 | 12 | 2<sup>9</sup> | 1.2 sec | 95 KB | | ||
| Merkle Proof (Poseidon, d=16) | 128 bits | 7 | 12 | 2<sup>10</sup> | 2.3 sec | 106 KB | | ||
| Merkle Proof (Poseidon, d=8) | 128 bits | 7 | 12 | 2<sup>9</sup> | 1.3 sec | 74 KB | | ||
| Merkle Proof (Poseidon, d=16) | 128 bits | 7 | 12 | 2<sup>10</sup> | 2.6 sec | 82 KB | | ||
@@ -218,0 +218,0 @@ STARKs in the above examples have security parameters set to provide ~96 bits security. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92240
1544