Skip to content

Commit

Permalink
feat(relay): Add MOCK mode to the relay
Browse files Browse the repository at this point in the history
  • Loading branch information
kkirkov committed Feb 23, 2024
1 parent 4d48bb6 commit a388abb
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 161 deletions.
2 changes: 1 addition & 1 deletion relay/abstraction/prover-interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Proof, ProofInputType } from '../types/types';

export interface IProver {
genProof(proofInput: ProofInputType): Promise<Proof>;
genProof(proofInput: ProofInputType, mock: boolean): Promise<Proof>;
}
68 changes: 50 additions & 18 deletions relay/implementations/prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,67 @@ export class Prover implements IProver {
this.proverServerURL = proverServerURL;
}

async genProof(proofInput: ProofInputType): Promise<Proof> {
logger.info('Starting to generate proofs');
async genProof(proofInput: ProofInputType, mock = false): Promise<Proof> {
var proof;
var publicVars;
if (!mock) {
logger.info('Starting to generate proofs');

let st = await this.getStatus();
let st = await this.getStatus();

if (st.status == 'busy') {
throw new Error('Proving server is not ready');
}

logger.info('Server is ready sending input');
if (st.status == 'busy') {
throw new Error('Proving server is not ready');
}

await this.callInput(proofInput.proofInput);
logger.info('Server is ready sending input');

logger.info('Input send waiting for proof generation');
await this.callInput(proofInput.proofInput);

st = await this.getStatus();
logger.info('Input send waiting for proof generation');

while (st.status == 'busy') {
st = await this.getStatus();

// to not overload server with requests
await new Promise(r => setTimeout(r, 2000));
}
while (st.status == 'busy') {
st = await this.getStatus();

logger.info('Proof successfully generated');
// to not overload server with requests
await new Promise(r => setTimeout(r, 2000));
}

const proof = JSON.parse(st.proof);
logger.info('Proof successfully generated');

const publicVars = JSON.parse(st.pubData);
proof = JSON.parse(st.proof);

publicVars = JSON.parse(st.pubData);
} else {
proof = {
pi_a: [
'12763925006581137919304949334797603802458106302550743441499138660117674458843',
'3210277313367297960978284600070647965688928976864111405932126995759004567274',
'1',
],
pi_b: [
[
'13262650684780645924631597816699461845882952491020847346256482683974830302382',
'18382552761441724027130145449451577465099488205434023208725500890682382654249',
],
[
'5742524743116358027698900120745802615824383991987775533210879169548095928215',
'9031854286059022594570625510067083999168656248388663258862090924521740417974',
],
['1', '0'],
],
pi_c: [
'13764977866279122478221420133386876215994100264892193449636036345427191382230',
'16905083775607366928536120749218882272365033612066779646866782727491849960912',
'1',
],
};
publicVars = [
'9734125334797249825003723072622467244897033234414344070397312864656672300128',
'4',
];
}

return {
pi_a: proof.pi_a,
Expand Down
Loading

0 comments on commit a388abb

Please sign in to comment.