Exemplo n.º 1
0
def create_pubvals_from_file(pubfile, pb):
    ff = pubfile.readlines()
    for i in range(len(ff)):
        pubv = libsnark.PbVariable()
        pubv.allocate(pb)
        pb.setpublic(pubv)
        pubval = int(ff[i].strip())
        pb.setval(pubv, pubval)

    pubvals = pb.primary_input_pubs()
    return pubvals
Exemplo n.º 2
0
def privval(val):
    pbv = libsnark.PbVariable()
    pbv.allocate(pb)
    pb.setval(pbv, val)
    return libsnark.LinearCombination(pbv)
Exemplo n.º 3
0
import sys

import libsnark.alt_bn128 as libsnark

#use this to get libsnark debugging output
#libsnark.cvar.inhibit_profiling_info = False

pb = libsnark.ProtoboardPub()

# create variables

inv = libsnark.PbVariable()
inv.allocate(pb)
pb.setpublic(inv)

int = libsnark.PbVariable()
int.allocate(pb)

outv = libsnark.PbVariable()
outv.allocate(pb)
pb.setpublic(outv)

# create constraints

# let int=inv*(2*inv+1)
pb.add_r1cs_constraint(
    libsnark.R1csConstraint(
        libsnark.LinearCombination(inv),
        libsnark.LinearCombination(inv) * 2 + libsnark.LinearCombination(1),
        libsnark.LinearCombination(int)))