Пример #1
0
func NewConstraintBuilder(specFile, pwsFile, qapAFile, qapBFile, qapCFile,
	f1IndexFile *os.File, outputTmpl bool) *ConstraintBuilder {
	cb := new(ConstraintBuilder)

	cb.buildSpec = specFile != nil
	cb.buildPWS = pwsFile != nil
	cb.buildQAP = qapAFile != nil && qapBFile != nil && qapCFile != nil
	cb.outputTmpl = outputTmpl

	if cb.buildSpec && (cb.buildPWS || cb.buildQAP) {
		log.Fatal("You can only output Spec or PWS and QAP, not both")
	}
	if cb.outputTmpl {
		if cb.buildSpec {
			log.Fatal("You can't build a Spec file as a template")
		}
		if !cb.buildPWS || !cb.buildQAP {
			log.Fatal("You must output PWS and QAP if you're building a template")
		}
	}

	cb.cmdsFile = util.OpenTempFile("cmds")
	if cb.buildSpec {
		cb.specFile = specFile
	}
	if cb.buildPWS {
		cb.pwsFile = pwsFile
	}
	if cb.buildQAP {
		cb.matFiles[0] = qapAFile
		cb.matFiles[1] = qapBFile
		cb.matFiles[2] = qapCFile
	}
	cb.f1IndexFile = f1IndexFile

	cb.varNumBits = make(map[string]int)
	cb.extVarIndices = make(map[string]int)

	cb.Zero = cb.Constant(0)
	cb.One = cb.Constant(1)

	return cb
}
Пример #2
0
func main() {
	var dbSize int
	flag.IntVar(&dbSize, "dbSize", 16, "")

	var hashType string
	flag.StringVar(&hashType, "hashType", "ggh", "")

	var fnames [3]string
	flag.StringVar(&fnames[0], "pwsFile", "", "")
	flag.StringVar(&fnames[1], "f1File", "", "")
	flag.StringVar(&fnames[2], "qapFile", "", "")

	flag.Parse()

	var files [3]*os.File
	util.OpenFiles(fnames[:], files[:])

	fmt.Fprintf(os.Stderr, "dbSize: %d\n", dbSize)

	var qapMats [3]*os.File
	for i := 0; i < 3; i++ {
		qapMats[i] = util.OpenTempFile("qapMat" + strconv.Itoa(i))
	}

	m := merkle.NewMerkle(dbSize, hashType, nil, files[0], qapMats[0], qapMats[1], qapMats[2], files[1], false)
	//	m.GenSumConstraints()
	//	m.GenGetPutConstraints()
	m.GenOp("get", 1)
	m.WriteFiles()

	qapFile := files[2]
	for i, f := range qapMats {
		util.CopyOrDie(qapFile, f)
		if i < len(qapMats)-1 {
			fmt.Fprintln(qapFile)
		}
	}
	qapFile.Close()

	m.GetCB().PrintParams(os.Stderr)
}