You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

875 lines
27 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. const errs = require("./errs");
  2. const buildWasmFf = require("ffwasm").buildWasmFf;
  3. module.exports = function buildRuntime(module, builder) {
  4. const pSanityCheck = module.alloc(4);
  5. function buildInit() {
  6. const f = module.addFunction("init");
  7. f.addParam("sanityCheck", "i32");
  8. f.addLocal("i", "i32");
  9. const c = f.getCodeBuilder();
  10. // Set the stack to current memory
  11. f.addCode(
  12. c.i32_store(
  13. c.i32_const(4),
  14. c.i32_shl(
  15. c.i32_and(
  16. c.current_memory(),
  17. c.i32_const(0xFFFFFFF8)
  18. ),
  19. c.i32_const(16)
  20. )
  21. )
  22. );
  23. // Save Sanity check flag
  24. f.addCode(
  25. c.i32_store(
  26. c.i32_const(pSanityCheck),
  27. c.getLocal("sanityCheck")
  28. )
  29. );
  30. f.addCode(
  31. // i=0
  32. c.setLocal("i", c.i32_const(0)),
  33. c.block(c.loop(
  34. // if (i==NComponents) break
  35. c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NComponents))),
  36. // inputSignalsToTrigger[i] = components[i].nInputSignals
  37. c.i32_store(
  38. c.i32_add(
  39. c.i32_const(builder.pInputSignalsToTrigger),
  40. c.i32_mul(
  41. c.getLocal("i"),
  42. c.i32_const(4)
  43. )
  44. ),
  45. c.i32_load(
  46. c.i32_add(
  47. c.i32_load(c.i32_const(builder.ppComponents)),
  48. c.i32_mul(
  49. c.getLocal("i"),
  50. c.i32_const(builder.sizeofComponent) // Sizeof component
  51. )
  52. ),
  53. builder.offsetComponentNInputSignals
  54. )
  55. ),
  56. // i=i+1
  57. c.setLocal(
  58. "i",
  59. c.i32_add(
  60. c.getLocal("i"),
  61. c.i32_const(1)
  62. )
  63. ),
  64. c.br(0)
  65. ))
  66. );
  67. f.addCode(ifSanityCheck(c,
  68. // i=0
  69. c.setLocal("i", c.i32_const(0)),
  70. c.block(c.loop(
  71. // if (i==NSignals) break
  72. c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NSignals))),
  73. // signalsAssigned[i] = false
  74. c.i32_store(
  75. c.i32_add(
  76. c.i32_const(builder.pSignalsAssigned),
  77. c.i32_mul(
  78. c.getLocal("i"),
  79. c.i32_const(4)
  80. )
  81. ),
  82. c.i32_const(0)
  83. ),
  84. // i=i+1
  85. c.setLocal(
  86. "i",
  87. c.i32_add(
  88. c.getLocal("i"),
  89. c.i32_const(1)
  90. )
  91. ),
  92. c.br(0)
  93. ))
  94. ));
  95. f.addCode(
  96. c.call(
  97. "Fr_copy",
  98. c.i32_const(builder.pSignals),
  99. c.i32_add(
  100. c.i32_load(c.i32_const(builder.ppConstants)),
  101. c.i32_const(builder.addConstant(1) * builder.sizeFr)
  102. )
  103. )
  104. );
  105. f.addCode(ifSanityCheck(c,
  106. c.i32_store(
  107. c.i32_const(builder.pSignalsAssigned),
  108. c.i32_const(1)
  109. )
  110. ));
  111. f.addCode(
  112. // i=0
  113. c.setLocal("i", c.i32_const(0)),
  114. c.block(c.loop(
  115. // if (i==NComponents) break
  116. c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NComponents))),
  117. // if (inputSignalsToTrigger[i] == 0) triggerComponent(i)
  118. c.if(
  119. c.i32_eqz(
  120. c.i32_load(
  121. c.i32_add(
  122. c.i32_const(builder.pInputSignalsToTrigger),
  123. c.i32_mul(
  124. c.getLocal("i"),
  125. c.i32_const(4)
  126. )
  127. )
  128. )
  129. ),
  130. c.call(
  131. "triggerComponent",
  132. c.getLocal("i")
  133. )
  134. ),
  135. // i=i+1
  136. c.setLocal(
  137. "i",
  138. c.i32_add(
  139. c.getLocal("i"),
  140. c.i32_const(1)
  141. )
  142. ),
  143. c.br(0)
  144. ))
  145. );
  146. }
  147. function ifSanityCheck(c, ...args) {
  148. return c.if(
  149. c.i32_load(c.i32_const(pSanityCheck)),
  150. [].concat(...[...args])
  151. );
  152. }
  153. function buildTriggerComponent() {
  154. const f = module.addFunction("triggerComponent");
  155. f.addParam("component", "i32");
  156. const c = f.getCodeBuilder();
  157. f.addCode(
  158. c.call_indirect(
  159. c.getLocal("component"), // Idx in table
  160. c.getLocal("component") // Parameter
  161. )
  162. );
  163. }
  164. function buildHash2ComponentEntry() {
  165. const f = module.addFunction("hash2ComponentEntry");
  166. f.addParam("component", "i32");
  167. f.addParam("hash", "i64");
  168. f.setReturnType("i32");
  169. f.addLocal("pComponent", "i32");
  170. f.addLocal("pHashTable", "i32");
  171. f.addLocal("hIdx", "i32");
  172. f.addLocal("h", "i64");
  173. const c = f.getCodeBuilder();
  174. f.addCode(
  175. c.setLocal(
  176. "pComponent",
  177. c.i32_add(
  178. c.i32_load(c.i32_const(builder.ppComponents)), // pComponents
  179. c.i32_mul(
  180. c.getLocal("component"),
  181. c.i32_const(20) // sizeof(Component)
  182. )
  183. )
  184. ),
  185. c.setLocal(
  186. "pHashTable",
  187. c.i32_load(c.getLocal("pComponent"))
  188. ),
  189. c.setLocal(
  190. "hIdx",
  191. c.i32_and(
  192. c.i32_wrap_i64(c.getLocal("hash")),
  193. c.i32_const(0xFF)
  194. )
  195. ),
  196. c.block(c.loop(
  197. c.setLocal(
  198. "h",
  199. c.i64_load(
  200. c.i32_add(
  201. c.getLocal("pHashTable"),
  202. c.i32_mul(
  203. c.getLocal("hIdx"),
  204. c.i32_const(12)
  205. )
  206. )
  207. )
  208. ),
  209. c.br_if(1, c.i64_eq(c.getLocal("h"), c.getLocal("hash"))),
  210. c.if(
  211. c.i64_eqz(c.getLocal("h")),
  212. c.call(
  213. "error",
  214. c.i32_const(errs.HASH_NOT_FOUND.code),
  215. c.i32_const(errs.HASH_NOT_FOUND.pointer),
  216. c.i32_const(0),
  217. c.i32_const(0),
  218. c.i32_const(0),
  219. c.i32_const(0)
  220. )
  221. ),
  222. c.setLocal(
  223. "hIdx",
  224. c.i32_and(
  225. c.i32_add(
  226. c.getLocal("hIdx"),
  227. c.i32_const(1)
  228. ),
  229. c.i32_const(0xFF)
  230. )
  231. ),
  232. c.br(0)
  233. )),
  234. c.i32_add( // pComponentEntry
  235. c.i32_load( // pComponentEntryTable
  236. c.i32_add(
  237. c.getLocal("pComponent"),
  238. c.i32_const(4)
  239. )
  240. ),
  241. c.i32_mul(
  242. c.i32_load( // idx to the componentEntry
  243. c.i32_add(
  244. c.getLocal("pHashTable"),
  245. c.i32_mul(
  246. c.getLocal("hIdx"),
  247. c.i32_const(12)
  248. )
  249. ),
  250. 8
  251. ),
  252. c.i32_const(12)
  253. )
  254. )
  255. );
  256. }
  257. function buildGetFromComponentEntry(fnName, offset, type) {
  258. const f = module.addFunction(fnName);
  259. f.addParam("pR", "i32");
  260. f.addParam("component", "i32");
  261. f.addParam("hash", "i64");
  262. f.addLocal("pComponentEntry", "i32");
  263. const c = f.getCodeBuilder();
  264. f.addCode(
  265. c.setLocal(
  266. "pComponentEntry",
  267. c.call(
  268. "hash2ComponentEntry",
  269. c.getLocal("component"),
  270. c.getLocal("hash")
  271. )
  272. ),
  273. c.if( // If type is not signal
  274. c.i32_ne(
  275. c.i32_load(
  276. c.getLocal("pComponentEntry"),
  277. 8 // type offset
  278. ),
  279. c.i32_const(type)
  280. ),
  281. c.call(
  282. "error",
  283. c.i32_const(errs.INVALID_TYPE.code),
  284. c.i32_const(errs.INVALID_TYPE.pointer),
  285. c.i32_const(0),
  286. c.i32_const(0),
  287. c.i32_const(0),
  288. c.i32_const(0)
  289. )
  290. ),
  291. c.i32_store(
  292. c.getLocal("pR"),
  293. c.i32_load(
  294. c.getLocal("pComponentEntry"),
  295. offset
  296. )
  297. )
  298. );
  299. const f2 = module.addFunction(fnName + "32");
  300. f2.addParam("pR", "i32");
  301. f2.addParam("component", "i32");
  302. f2.addParam("hashMSB", "i32");
  303. f2.addParam("hashLSB", "i32");
  304. const c2 = f2.getCodeBuilder();
  305. f2.addCode(
  306. c2.call(
  307. fnName,
  308. c2.getLocal("pR"),
  309. c2.getLocal("component"),
  310. c2.i64_or(
  311. c2.i64_shl(
  312. c2.i64_extend_i32_u(c2.getLocal("hashMSB")),
  313. c2.i64_const(32)
  314. ),
  315. c2.i64_extend_i32_u(c2.getLocal("hashLSB"))
  316. )
  317. )
  318. );
  319. }
  320. function buildGetSignal() {
  321. const f = module.addFunction("getSignal");
  322. f.addParam("cIdx", "i32");
  323. f.addParam("pR", "i32");
  324. f.addParam("component", "i32");
  325. f.addParam("signal", "i32");
  326. const c = f.getCodeBuilder();
  327. f.addCode(ifSanityCheck(c,
  328. c.if(
  329. c.i32_eqz(
  330. c.i32_load(
  331. c.i32_add(
  332. c.i32_const(builder.pSignalsAssigned),
  333. c.i32_mul(
  334. c.getLocal("signal"),
  335. c.i32_const(4)
  336. )
  337. ),
  338. )
  339. ),
  340. c.call(
  341. "error",
  342. c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.code),
  343. c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer),
  344. c.getLocal("cIdx"),
  345. c.getLocal("component"),
  346. c.getLocal("signal"),
  347. c.i32_const(0)
  348. )
  349. )
  350. ));
  351. f.addCode(
  352. c.call(
  353. "Fr_copy",
  354. c.getLocal("pR"),
  355. c.i32_add(
  356. c.i32_const(builder.pSignals),
  357. c.i32_mul(
  358. c.getLocal("signal"),
  359. c.i32_const(builder.sizeFr)
  360. )
  361. )
  362. )
  363. );
  364. f.addCode(ifSanityCheck(c,
  365. c.call("logGetSignal", c.getLocal("signal"), c.getLocal("pR") )
  366. ));
  367. }
  368. function buildSetSignal() {
  369. const f = module.addFunction("setSignal");
  370. f.addParam("cIdx", "i32");
  371. f.addParam("component", "i32");
  372. f.addParam("signal", "i32");
  373. f.addParam("pVal", "i32");
  374. f.addLocal("signalsToTrigger", "i32");
  375. const c = f.getCodeBuilder();
  376. f.addCode(ifSanityCheck(c,
  377. c.call("logSetSignal", c.getLocal("signal"), c.getLocal("pVal") ),
  378. c.if(
  379. c.i32_load(
  380. c.i32_add(
  381. c.i32_const(builder.pSignalsAssigned),
  382. c.i32_mul(
  383. c.getLocal("signal"),
  384. c.i32_const(4)
  385. )
  386. ),
  387. ),
  388. c.call(
  389. "error",
  390. c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.code),
  391. c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.pointer),
  392. c.i32_const(0),
  393. c.i32_const(0),
  394. c.i32_const(0),
  395. c.i32_const(0)
  396. )
  397. ),
  398. c.i32_store(
  399. c.i32_add(
  400. c.i32_const(builder.pSignalsAssigned),
  401. c.i32_mul(
  402. c.getLocal("signal"),
  403. c.i32_const(4)
  404. )
  405. ),
  406. c.i32_const(1)
  407. ),
  408. ));
  409. f.addCode(
  410. c.call(
  411. "Fr_copy",
  412. c.i32_add(
  413. c.i32_const(builder.pSignals),
  414. c.i32_mul(
  415. c.getLocal("signal"),
  416. c.i32_const(builder.sizeFr)
  417. )
  418. ),
  419. c.getLocal("pVal"),
  420. )
  421. );
  422. f.addCode(
  423. c.if( // If ( mapIsInput[s >> 5] & (1 << (s & 0x1f)) )
  424. c.i32_and(
  425. c.i32_load(
  426. c.i32_add(
  427. c.i32_load(c.i32_const(builder.ppMapIsInput)),
  428. c.i32_shl(
  429. c.i32_shr_u(
  430. c.getLocal("signal"),
  431. c.i32_const(5)
  432. ),
  433. c.i32_const(2)
  434. )
  435. )
  436. ),
  437. c.i32_shl(
  438. c.i32_const(1),
  439. c.i32_and(
  440. c.getLocal("signal"),
  441. c.i32_const(0x1F)
  442. )
  443. )
  444. ),
  445. [
  446. ...c.setLocal(
  447. "signalsToTrigger",
  448. c.i32_load(
  449. c.i32_add(
  450. c.i32_const(builder.pInputSignalsToTrigger),
  451. c.i32_mul(
  452. c.getLocal("component"),
  453. c.i32_const(4)
  454. )
  455. )
  456. )
  457. ),
  458. ...c.if( // if (signalsToTrigger > 0)
  459. c.i32_gt_u(
  460. c.getLocal("signalsToTrigger"),
  461. c.i32_const(0)
  462. ),
  463. [
  464. ...c.setLocal( // signalsToTrigger--
  465. "signalsToTrigger",
  466. c.i32_sub(
  467. c.getLocal("signalsToTrigger"),
  468. c.i32_const(1)
  469. )
  470. ),
  471. ...c.i32_store(
  472. c.i32_add(
  473. c.i32_const(builder.pInputSignalsToTrigger),
  474. c.i32_mul(
  475. c.getLocal("component"),
  476. c.i32_const(4)
  477. )
  478. ),
  479. c.getLocal("signalsToTrigger"),
  480. ),
  481. ...c.if( // if (signalsToTrigger==0) triggerCompomnent(component)
  482. c.i32_eqz(c.getLocal("signalsToTrigger")),
  483. c.call(
  484. "triggerComponent",
  485. c.getLocal("component")
  486. )
  487. )
  488. ],
  489. c.call(
  490. "error",
  491. c.i32_const(errs.MAPISINPUT_DONT_MATCH.code),
  492. c.i32_const(errs.MAPISINPUT_DONT_MATCH.pointer),
  493. c.getLocal("component"),
  494. c.getLocal("signal"),
  495. c.i32_const(0),
  496. c.i32_const(0)
  497. )
  498. )
  499. ]
  500. )
  501. );
  502. }
  503. function buildComponentFinished() {
  504. const f = module.addFunction("componentFinished");
  505. f.addParam("cIdx", "i32");
  506. const c = f.getCodeBuilder();
  507. f.addCode(ifSanityCheck(c,
  508. c.call("logFinishComponent", c.getLocal("cIdx"))
  509. ));
  510. f.addCode(c.ret([]));
  511. }
  512. function buildComponentStarted() {
  513. const f = module.addFunction("componentStarted");
  514. f.addParam("cIdx", "i32");
  515. const c = f.getCodeBuilder();
  516. f.addCode(ifSanityCheck(c,
  517. c.call("logStartComponent", c.getLocal("cIdx"))
  518. ));
  519. f.addCode(c.ret([]));
  520. }
  521. function buildCheckConstraint() {
  522. const pTmp = module.alloc(builder.sizeFr);
  523. const f = module.addFunction("checkConstraint");
  524. f.addParam("cIdx", "i32");
  525. f.addParam("pA", "i32");
  526. f.addParam("pB", "i32");
  527. f.addParam("pStr", "i32");
  528. const c = f.getCodeBuilder();
  529. f.addCode(ifSanityCheck(c,
  530. c.call(
  531. "Fr_eq",
  532. c.i32_const(pTmp),
  533. c.getLocal("pA"),
  534. c.getLocal("pB")
  535. ),
  536. c.if (
  537. c.i32_eqz(
  538. c.call(
  539. "Fr_isTrue",
  540. c.i32_const(pTmp),
  541. )
  542. ),
  543. c.call(
  544. "error",
  545. c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.code),
  546. c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.pointer),
  547. c.getLocal("cIdx"),
  548. c.getLocal("pA"),
  549. c.getLocal("pB"),
  550. c.getLocal("pStr"),
  551. )
  552. )
  553. ));
  554. }
  555. function buildCheckAssert() {
  556. const f = module.addFunction("checkAssert");
  557. f.addParam("cIdx", "i32");
  558. f.addParam("pA", "i32");
  559. f.addParam("pStr", "i32");
  560. const c = f.getCodeBuilder();
  561. f.addCode(ifSanityCheck(c,
  562. c.if (
  563. c.i32_eqz(
  564. c.call(
  565. "Fr_isTrue",
  566. c.getLocal("pA"),
  567. )
  568. ),
  569. c.call(
  570. "error",
  571. c.i32_const(errs.ASSERT_DOES_NOT_MATCH.code),
  572. c.i32_const(errs.ASSERT_DOES_NOT_MATCH.pointer),
  573. c.getLocal("cIdx"),
  574. c.getLocal("pA"),
  575. c.getLocal("pStr"),
  576. c.i32_const(0)
  577. )
  578. )
  579. ));
  580. }
  581. function buildGetNVars() {
  582. const f = module.addFunction("getNVars");
  583. f.setReturnType("i32");
  584. const c = f.getCodeBuilder();
  585. f.addCode(c.i32_const(builder.header.NVars));
  586. }
  587. function buildGetFrLen() {
  588. const f = module.addFunction("getFrLen");
  589. f.setReturnType("i32");
  590. const c = f.getCodeBuilder();
  591. f.addCode(
  592. c.i32_const(builder.sizeFr));
  593. }
  594. function buildGetPRawPrime() {
  595. const f = module.addFunction("getPRawPrime");
  596. f.setReturnType("i32");
  597. const c = f.getCodeBuilder();
  598. f.addCode(
  599. c.i32_const(module.modules["Fr_F1m"].pq));
  600. }
  601. function buildGetPWitness() {
  602. const f = module.addFunction("getPWitness");
  603. f.addParam("w", "i32");
  604. f.addLocal("signal", "i32");
  605. f.setReturnType("i32");
  606. const c = f.getCodeBuilder();
  607. f.addCode(
  608. c.setLocal(
  609. "signal",
  610. c.i32_load( // wit2sig[w]
  611. c.i32_add(
  612. c.i32_load( c.i32_const(builder.ppWit2sig)),
  613. c.i32_mul(
  614. c.getLocal("w"),
  615. c.i32_const(4)
  616. )
  617. )
  618. )
  619. )
  620. );
  621. if (builder.sanityCheck) {
  622. f.addCode(
  623. c.if(
  624. c.i32_eqz(
  625. c.i32_load(
  626. c.i32_add(
  627. c.i32_const(builder.pSignalsAssigned),
  628. c.i32_mul(
  629. c.getLocal("signal"),
  630. c.i32_const(4)
  631. )
  632. ),
  633. )
  634. ),
  635. c.call(
  636. "error",
  637. c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.code),
  638. c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer),
  639. c.i32_const(0),
  640. c.i32_const(0),
  641. c.i32_const(0),
  642. c.i32_const(0)
  643. )
  644. )
  645. );
  646. }
  647. f.addCode(
  648. c.i32_add(
  649. c.i32_const(builder.pSignals),
  650. c.i32_mul(
  651. c.getLocal("signal"),
  652. c.i32_const(builder.sizeFr)
  653. )
  654. )
  655. );
  656. }
  657. function buildGetWitnessBuffer() {
  658. const f = module.addFunction("getWitnessBuffer");
  659. f.setReturnType("i32");
  660. f.addLocal("i", "i32");
  661. f.addLocal("pSrc", "i32");
  662. f.addLocal("pDst", "i32");
  663. const c = f.getCodeBuilder();
  664. f.addCode(
  665. c.setLocal("i", c.i32_const(0)),
  666. c.block(c.loop(
  667. // if (i==NComponents) break
  668. c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NVars))),
  669. c.setLocal(
  670. "pSrc",
  671. c.call(
  672. "getPWitness",
  673. c.getLocal("i"),
  674. )
  675. ),
  676. c.call(
  677. "Fr_toLongNormal",
  678. c.getLocal("pSrc")
  679. ),
  680. c.setLocal(
  681. "pDst",
  682. c.i32_add(
  683. c.i32_const(builder.pOutput),
  684. c.i32_mul(
  685. c.getLocal("i"),
  686. c.i32_const(builder.sizeFr-8)
  687. )
  688. )
  689. ),
  690. c.call(
  691. "Fr_F1m_copy",
  692. c.i32_add(c.getLocal("pSrc"), c.i32_const(8)),
  693. c.getLocal("pDst")
  694. ),
  695. // i=i+1
  696. c.setLocal(
  697. "i",
  698. c.i32_add(
  699. c.getLocal("i"),
  700. c.i32_const(1)
  701. )
  702. ),
  703. c.br(0)
  704. )),
  705. c.i32_const(builder.pOutput)
  706. );
  707. }
  708. const fError = module.addIimportFunction("error", "runtime");
  709. fError.addParam("code", "i32");
  710. fError.addParam("pStr", "i32");
  711. fError.addParam("param1", "i32");
  712. fError.addParam("param2", "i32");
  713. fError.addParam("param3", "i32");
  714. fError.addParam("param4", "i32");
  715. const fLogSetSignal = module.addIimportFunction("logSetSignal", "runtime");
  716. fLogSetSignal.addParam("signal", "i32");
  717. fLogSetSignal.addParam("val", "i32");
  718. const fLogGetSignal = module.addIimportFunction("logGetSignal", "runtime");
  719. fLogGetSignal.addParam("signal", "i32");
  720. fLogGetSignal.addParam("val", "i32");
  721. const fLogFinishComponent = module.addIimportFunction("logFinishComponent", "runtime");
  722. fLogFinishComponent.addParam("cIdx", "i32");
  723. const fLogStartComponent = module.addIimportFunction("logStartComponent", "runtime");
  724. fLogStartComponent.addParam("cIdx", "i32");
  725. const fLog = module.addIimportFunction("log", "runtime");
  726. fLog.addParam("code", "i32");
  727. buildWasmFf(module, "Fr", builder.header.P);
  728. builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr);
  729. builder.pOutput=module.alloc(builder.header.NVars*(builder.sizeFr-8));
  730. builder.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4);
  731. builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4);
  732. buildHash2ComponentEntry();
  733. buildTriggerComponent();
  734. buildInit();
  735. buildGetFromComponentEntry("getSubComponentOffset", 0 /* offset */, builder.TYPE_COMPONENT);
  736. buildGetFromComponentEntry("getSubComponentSizes", 4 /* offset */, builder.TYPE_COMPONENT);
  737. buildGetFromComponentEntry("getSignalOffset", 0 /* offset */, builder.TYPE_SIGNAL);
  738. buildGetFromComponentEntry("getSignalSizes", 4 /* offset */, builder.TYPE_SIGNAL);
  739. buildGetSignal();
  740. buildSetSignal();
  741. buildComponentStarted();
  742. buildComponentFinished();
  743. buildCheckConstraint();
  744. buildCheckAssert();
  745. buildGetNVars();
  746. buildGetFrLen();
  747. buildGetPWitness();
  748. buildGetPRawPrime();
  749. buildGetWitnessBuffer();
  750. // buildFrToInt();
  751. module.exportFunction("init");
  752. module.exportFunction("getNVars");
  753. module.exportFunction("getFrLen");
  754. module.exportFunction("getSignalOffset32");
  755. module.exportFunction("setSignal");
  756. module.exportFunction("getPWitness");
  757. module.exportFunction("Fr_toInt");
  758. module.exportFunction("getPRawPrime");
  759. module.exportFunction("getWitnessBuffer");
  760. };