circom/wasm/AddSum.cpp
wasm/AddSum.cppRaw
1
2class Value {
3
4}
5
6class Var : Value {
7
8}
9
10class Ctx {
11 char *currentComponent;
12
13 Var getParam(char *);
14 Var getSignal(char *, ...);
15
16 Var newVar(char *);
17}
18
19
20
21
22
23void Num2Bits::Num2Bits(ctx) {
24 Var n = ctx.getParam("n");
25 Var in = ctx.getSignal("in");
26 Var out = ctx.getSignal("out");
27 (Var lc1 = ctx.newVar()) = _0x0;
28
29 for ((Var i = ctx.newVar()) = _0x0 ; i<n; i++ ) {
30 out[i] = (in >> i) & _0x1;
31 assert(out[i]*(out[i] - _0x1), _0x0);
32 lc1 += out[i] * (2**i);
33 }
34
35 assert(lc1, in);
36}