From b9dfbd4d10fc42ffef098373474545a5cd5723a2 Mon Sep 17 00:00:00 2001 From: siq1 Date: Wed, 11 Sep 2024 00:34:36 +0700 Subject: [PATCH] add simple tobinary implement --- ecgo/builder/api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ecgo/builder/api.go b/ecgo/builder/api.go index 6846028..c3d4abc 100644 --- a/ecgo/builder/api.go +++ b/ecgo/builder/api.go @@ -135,7 +135,16 @@ func (builder *builder) Inverse(i1 frontend.Variable) frontend.Variable { // // The result in in little endian (first bit= lsb) func (builder *builder) ToBinary(i1 frontend.Variable, n ...int) []frontend.Variable { - panic("unimplemented") + // TODO: Currently this doesn't support MarkBoolean + nbBits := builder.field.FieldBitLen() + if len(n) == 1 { + nbBits = n[0] + if nbBits < 0 { + panic("invalid n") + } + } + + return bits.ToBinary(builder, i1, bits.WithNbDigits(nbBits)) } // FromBinary packs the given variables, seen as a fr.Element in little endian, into a single variable.