circom-2-arithc(-ts)
May 14, 2024 ยท View on GitHub
TypeScript library for compiling circom to arithmetic circuits backed by namnc/circom-2-arithc.
Usage
npm install circom-2-arithc
import * as c2a from 'circom-2-arithc';
async function main() {
await c2a.init();
const circuitSrc = {
// In a real project you should be able to include these as regular files,
// but how those files find their way into this format depends on your build
// tool.
'/src/main.circom': `
pragma circom 2.0.0;
template Adder() {
signal input a, b;
signal output c;
c <== a + b;
}
component main = Adder();
`,
};
const circuit = c2a.Circuit.compile(circuitSrc);
console.log(
// In future named inputs and outputs should work via
// `circuit.eval({ a: 3, b: 5 })`
circuit.evalArray(new Uint32Array([3, 5])),
); // [8]
// For use with mpz-ts, use `circuit.toMpzCircuit()` (not yet implemented).
}
main().catch(console.error);
Development
Build with npm run build. This will compile the wasm subproject and also
transpile typescript into javascript. Rust toolchain
required.
Test with npm test.
Example Project
Web demo using this module: https://voltrevo.github.io/circom-2-arithc-ts-demo.
We are also working towards a more complete MPC demo, but mpz-ts is not yet implemented.