Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: privacy-scaling-explorations/mpc-framework-common
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: debucmunity/mpc-framework-common
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 12 commits
  • 6 files changed
  • 2 contributors

Commits on May 9, 2025

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    fa3ae24 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2192686 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    8482511 View commit details
  4. upload

    quanghoang112 authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c39f76a View commit details
  5. Update README.md

    quanghoang112 authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    001346d View commit details
  6. Update new_val.ts

    quanghoang112 authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    39a1563 View commit details
  7. Update new_val.ts

    quanghoang112 authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1c12a90 View commit details
  8. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a2f9e4b View commit details
  9. Update package.json

    quanghoang112 authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    972298a View commit details
  10. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1950669 View commit details
  11. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ef5e189 View commit details
  12. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    87c9df7 View commit details
Showing with 188 additions and 32 deletions.
  1. +12 −0 README.md
  2. +129 −0 ReadText/new_val.ts
  3. +3 −0 package.json
  4. +36 −32 tests/checkSettingsValid.test.ts
  5. +7 −0 text/bristol-circuit.txt
  6. +1 −0 text/circuit-info.txt
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# mpc-framework-common

Supporting module for working with mpc-framework.

## How to run
- install package:
```
npm i
```

- Run test:
```
npm run test
```

129 changes: 129 additions & 0 deletions ReadText/new_val.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
'use strict';

import { Circuit,CircuitIOInfo,MpcParticipantSettings } from "../src/types";
import * as fs from 'fs';
import * as path from 'path';
// process.stdin.resume();
// process.stdin.setEncoding('utf-8');
import {open,} from 'node:fs/promises';

function dupicate_character(str: string, num: number): string {
let result = '';
for (let i = 0; i < num; i++) {
result += ` ${str}`;
}
return result;
}

async function readFileFromCircuit(filePath: string): Promise<string[]> {
const file = await open(filePath, 'r');
let lines: string[] =[];
for await (const line of file.readLines()) {
lines.push(line);
}
return lines;
}


function to_Bristol_format(lines: string[]): string[] {
let ans: string[] = [];
let chars: string[][] = [];
for (let i of lines)
chars.push(i.split(" "));
// console.log(chars);
for (let i=4;i<lines.length;i++)
{
let sum_wire: number =Number(chars[i][0]) + Number(chars[i][1])
let first_line = `1 ${sum_wire} \n`;
let dup_input=dupicate_character(`1`, Number(chars[i][0]));
let dup_output=dupicate_character(`1`, Number(chars[i][1]));
let tmp: string = `${first_line} ${Number(chars[i][0])}${dup_input} \n` + ` ${Number(chars[i][1])}${dup_output} \n \n `;

ans.push(tmp + lines[i])
}
return ans;
}


async function readFileFromCircuitInfo(filePath: string): Promise<string> {
const file = await open(filePath, 'r');
let lines: string[] =[];
for await (const line of file.readLines()) {
lines.push(line);
}
return lines[0];
}

// function getMPCsettings(circuit: string):


export async function create_(circuitfile: string, circuitInfofile: string): Promise<Circuit> {
const circuitPath = circuitfile; // Thay bằng đường dẫn thực tế
const circuitInfoPath = circuitInfofile; // Thay bằng đường dẫn thực tế
const Arith_bristol = await readFileFromCircuit(circuitPath);
const circuitInfo = JSON.parse(await readFileFromCircuitInfo(circuitInfoPath));
// console.log(circuitInfo);
let inputs: CircuitIOInfo[] = [];

for (let i of circuitInfo.inputs) {
inputs.push({
name: i.name,
type: i.type,
address: i.address,
width: i.width,
});
}

let outputs: CircuitIOInfo[] = [];
for (let i of circuitInfo.outputs) {
outputs.push({
name: i.name,
type: i.type,
address: i.address,
width: i.width,
});
}
let input_for_A: string[] = [];
let input_for_B: string[] = [];
for (let i = 0; i< inputs.length; i++) {
if (i < Math.floor(inputs.length / 2)) {
input_for_A.push(inputs[i].name);
} else {
input_for_B.push(inputs[i].name);
}
}

let output_name: string[] = [];
for (let i = 0; i< outputs.length; i++) {
output_name.push(outputs[i].name);
}

let testcase: Circuit = {
bristol: Arith_bristol.join('\n'),
info: {
constants: [],
inputs: inputs,
outputs: outputs,
},
mpcSettings: [
{
name: 'alice',
inputs: input_for_A,
outputs: output_name,
},
{
name: 'bob',
inputs: input_for_B,
outputs: output_name,
},
],
}
// console.log(input_for_A);
// console.log(input_for_B);
// console.log(output_name);
// console.log(testcase.bristol);
// console.log(testcase.info);
// console.log(testcase.mpcSettings);
return testcase;
}

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@
"url": "git+https://github.com/voltrevo/mpc-framework-common.git"
},
"license": "MIT",
"dependencies": {
"@types/node": "^7.0.5"
},
"devDependencies": {
"@types/chai": "^4.3.17",
"@types/mocha": "^10.0.7",
68 changes: 36 additions & 32 deletions tests/checkSettingsValid.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
import { expect } from "chai";
import { checkSettingsValid, Circuit } from "../src";

const aPlusB: Circuit = {
bristol: [
'1 3',
'2 1 1',
'1 1',
'',
'2 1 0 1 2 AAddB',
].join('\n'),
info: {
constants: [],
inputs: [
{ name: 'a', type: 'number', address: 0, width: 1 },
{ name: 'b', type: 'number', address: 1, width: 1 },
],
outputs: [
{ name: 'c', type: 'number', address: 2, width: 1 },
],
},
mpcSettings: [
{
name: 'alice',
inputs: ['a'],
outputs: ['c'],
},
{
name: 'bob',
inputs: ['b'],
outputs: ['c'],
},
],
};
import {create_} from "../ReadText/new_val";

const aPlusB=await create_('./text/bristol-circuit.txt', './text/circuit-info.txt');

// const aPlusB: Circuit = {
// bristol: [
// '1 3',
// '2 1 1',
// '1 1',
// '',
// '2 1 0 1 2 AAddB',
// ].join('\n'),
// info: {
// constants: [],
// inputs: [
// { name: 'a', type: 'number', address: 0, width: 1 },
// { name: 'b', type: 'number', address: 1, width: 1 },
// ],
// outputs: [
// { name: 'c', type: 'number', address: 2, width: 1 },
// ],
// },
// mpcSettings: [
// {
// name: 'alice',
// inputs: ['a'],
// outputs: ['c'],
// },
// {
// name: 'bob',
// inputs: ['b'],
// outputs: ['c'],
// },
// ],
// };

describe('checkSettingsValid', () => {
it('accepts valid settings', () => {
const checkResult = checkSettingsValid(
aPlusB,
'alice',
{ a: 3 },
{ input0: 3, input1: 4, input2: 5 },
);

expect(checkResult).to.be.undefined;
7 changes: 7 additions & 0 deletions text/bristol-circuit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
3 9
6 1 1 1 1 1 1
3 1 1 1

2 1 0 1 2 AAdd
2 1 3 4 5 ASub
2 1 6 7 8 AMul
1 change: 1 addition & 0 deletions text/circuit-info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"constants":[],"inputs":[{"name":"input0","type":"number","address":0,"width":1},{"name":"input1","type":"number","address":1,"width":1},{"name":"input2","type":"number","address":3,"width":1},{"name":"input3","type":"number","address":4,"width":1},{"name":"input4","type":"number","address":6,"width":1},{"name":"input5","type":"number","address":7,"width":1}],"outputs":[{"name":"output0","type":"number","address":2,"width":1},{"name":"output1","type":"number","address":5,"width":1},{"name":"output2","type":"number","address":8,"width":1}]}