Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement API using non-native field emulation #325

Merged
merged 9 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion frontend/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Compile(field *big.Int, newBuilder NewBuilder, circuit Circuit, opts ...Com
log := logger.Logger()
log.Info().Msg("compiling circuit")
// parse options
opt := CompileConfig{}
opt := CompileConfig{wrapper: func(b Builder) Builder { return b }}
for _, o := range opts {
if err := o(&opt); err != nil {
log.Err(err).Msg("applying compile option")
Expand All @@ -47,6 +47,7 @@ func Compile(field *big.Int, newBuilder NewBuilder, circuit Circuit, opts ...Com
log.Err(err).Msg("instantiating builder")
return nil, fmt.Errorf("new compiler: %w", err)
}
builder = opt.wrapper(builder)

// parse the circuit builds a schema of the circuit
// and call circuit.Define() method to initialize a list of constraints in the compiler
Expand Down Expand Up @@ -139,6 +140,7 @@ type CompileOption func(opt *CompileConfig) error
type CompileConfig struct {
Capacity int
IgnoreUnconstrainedInputs bool
wrapper BuilderWrapper
}

// WithCapacity is a compile option that specifies the estimated capacity needed
Expand All @@ -165,6 +167,19 @@ func IgnoreUnconstrainedInputs() CompileOption {
}
}

// BuilderWrapper wraps existing Builder.
type BuilderWrapper func(Builder) Builder

// WithBuilderWrapper is a compile option which wraps the builder before parsing
// the schema and calling Define method of the circuit. If not set, then the
// builder returned by the NewBuilder is directly used.
func WithBuilderWrapper(wrapper BuilderWrapper) CompileOption {
return func(opt *CompileConfig) error {
opt.wrapper = wrapper
return nil
}
}

var tVariable reflect.Type

func init() {
Expand Down
Loading