Skip to content

Commit

Permalink
working circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
koalateectrl committed Oct 25, 2024
1 parent acd386e commit 1a245b5
Show file tree
Hide file tree
Showing 15 changed files with 512 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

#Computer files
.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Foundry
## ZK Circuit Education Module

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Expand Down
9 changes: 9 additions & 0 deletions circuits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Circom Usage

Assuming you are currently in this folder,

1. `circom multiplier2.circom --r1cs --wasm`

2. `node multiplier2_js/generate_witness.js multiplier2_js/multiplier2.wasm input.json witness.wtns`

3.
1 change: 1 addition & 0 deletions circuits/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a": "3", "b": "11"}
16 changes: 16 additions & 0 deletions circuits/multiplier2.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma circom 2.1.8;

/*This circuit template checks that c is the multiplication of a and b.*/

template Multiplier2 () {

// Declaration of signals.
signal input a;
signal input b;
signal output c;

// Constraints.
c <== a * b;
}

component main = Multiplier2();
Binary file added circuits/multiplier2.r1cs
Binary file not shown.
Binary file added circuits/multiplier2_0000.zkey
Binary file not shown.
Binary file added circuits/multiplier2_0001.zkey
Binary file not shown.
20 changes: 20 additions & 0 deletions circuits/multiplier2_js/generate_witness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const wc = require("./witness_calculator.js");
const { readFileSync, writeFile } = require("fs");

if (process.argv.length != 5) {
console.log("Usage: node generate_witness.js <file.wasm> <input.json> <output.wtns>");
} else {
const input = JSON.parse(readFileSync(process.argv[3], "utf8"));

const buffer = readFileSync(process.argv[2]);
wc(buffer).then(async witnessCalculator => {
// const w= await witnessCalculator.calculateWitness(input,0);
// for (let i=0; i< w.length; i++){
// console.log(w[i]);
// }
const buff= await witnessCalculator.calculateWTNSBin(input,0);
writeFile(process.argv[4], buff, function(err) {
if (err) throw err;
});
});
}
Binary file added circuits/multiplier2_js/multiplier2.wasm
Binary file not shown.
Loading

0 comments on commit 1a245b5

Please sign in to comment.